Mould Diary Day2

Today's Goal

  1. Retrospective JYU Test Title
  2. Brush Title

JYU Training Contest Title

Check-in this topic
Product modulus equals two multipliers modulus and multiply
Remember to modulus the product again

ac code
#include<stdio.h>
int main()
{
	unsigned long long a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	--a;
	a%=c;  b%=c;
	printf("%lld",a*b%c);
	return 0;
}

A simple dfs, similar to the full permutation problem, uses the DFS enumeration in all cases and determines whether or not it is a prime number.

ac code
#include<stdio.h>
#include<math.h>
int a[21],sum,n,m;
long long ans;
bool isprime(int n)
{
	for(int i=2;i<=sqrt(n);i++)
	    if(n%i==0) return false;
	return true;
}
void dfs(int x,int sum,int c)
{
	if(x==m){
		if(isprime(sum))
		ans++;
		return ;
	}
	for(int i=c;i<n;i++){
		dfs(x+1,sum+a[i],i+1);
	}
} 
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	dfs(0,0,0);
	printf("%lld",ans);
	return 0;
}


This question finds the longest continuous sequence, opens a 107 array, sorts the input numbers directly in buckets, and then traverses the array to find the longest continuous sequence.It is important to note that too much data requires fast reading.

ac code
#include<stdio.h>
#include<algorithm>
inline int read(){
    int s = 0, w = 1; char ch = getchar();
    while(ch < '0' || ch > '9'){ 
	    if(ch == '-') w = -1;   ch = getchar();
	}
    while(ch >= '0' && ch <= '9'){
    	s = s * 10 + ch - '0';  ch = getchar();
	}
    return s * w;
} 
using namespace std;
int cmp(int x,int y){
	return x<y?x:y;
}
int a[10100000];
int main()
{
	int n,m,c,maxx=-1,ans=1,num=1;
	n = read();
	for(int i=0;i<n;i++){
		c = read();
		a[c]=1;
		maxx=max(c,maxx);
	}
	for(int i=1;i<=maxx;i++){
		if(a[i-1]&&a[i]){
			num++;
		}
		else num=1;
		ans=max(ans,num);
	}
	printf("%d",ans);
	return 0;
}

Check-in question, the direct subscript indicates the age array count.

ac code
#include<stdio.h>
int a[51];
int main()
{
	int n,c;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&c);  a[c]++;
	}
	for(int i=0;i<=51;i++){
		if(a[i]>0){
			printf("%d:%d\n",i,a[i]);
		}
	}
	return 0;
}


When n=1, ans=1;1
When n=2, ans=4; 1 2 12 21
When n=3, ans=12; 1 2 3 12 13 23 21 32 123 231 321
When n=4, ans=26; 1 2 3 4 12 13 14 21 24 31 32 34 41 42 43 124 134 213 214 234 321 324 314 412 413 423 1234 2314 4321 3124
It is not difficult to find that each n corresponds to n*2n-1 scenarios

ac code
#include<stdio.h>
long long mod=1000000007;
long long f(long long  a, long long b, long long m){
	long long  ans = 1;
	while(b > 0){
		if(b & 1){
			ans = ans * a % m;
		}
		a = a * a % m;
		b >>= 1; 
	} 
	return ans;
}
int main()
{
	long long n;
	scanf("%lld",&n);
	if(n==1) printf("1");
	else{
		printf("%lld",(n*f(2,n-1,mod))%mod);
	}
	return 0;
}

Expand

Quick Read In

Program card constant, generally refers to a program whose asymptotic complexity is acceptable, but the large time constant factor of the implementation/algorithm itself makes it impossible to run within the time limit set by the OI/ICPC algorithm contest.

Constants are called the most magical kind of numbers in computer algorithm contests, and their main features are focused on elusive numbers that can sometimes confuse high-level players with timeouts or hyperspaces.

Quick read is required when there is too much or too much data read in the test case.

Quick Read Template
inline int read(){
    int s = 0, w = 1; char ch = getchar();
    while(ch < '0' || ch > '9'){ 
         if(ch == '-') w = -1; ch = getchar();
    }
    while(ch >= '0' && ch <= '9') {
         s = s * 10 + ch - '0';ch = getchar();
    }
    return s * w;
} // This is a C++ quick-read template for negative numbers

The principle is to use the feature that getchar() reads faster than cin and scanf.

Two original articles have been published. Approved 0. Visits 18
Private letter follow

Posted on Fri, 31 Jan 2020 20:06:54 -0500 by Sooz719