2019 Jiamusi training Day5

    T1

  Flood problem, the question was how do you Zhashui, AC

  Ideas: flood problem

  
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int t;
 4 long long n,ans;
 5 int main(){
 6     scanf("%d",&t);
 7     while(t--){
 8         scanf("%lld",&n);
 9         ans=0;
10         if(n==1){printf("0\n");continue;}
11         while(n!=1){
12             while(n%2==0) ans+=1,n/=2;
13             while(n%3==0) ans+=2,n/=3;
14             while(n%5==0) ans+=3,n/=5;
15             if(n==1) break;
16             if(n%2!=0&&n%3!=0&&n%5!=0){ans=-1;break;}
17         }
18         printf("%lld\n",ans);
19     }
20     return 0;
21 }
T1-A

    T2

  Thinking questions, more detail, the general is not difficult

  zkc Gangster remind you: OI futile decade, not open long long to see fathers

  Ideas: Analog deque sequence found in the largest value in the first time,

We can determine, he would later sequence in the first position by a maximum of one

Infinite loop, we were just special sentence can be.

 

  
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 long long n,nq,tail;
 4 long long x,qwq,stop,maxx,ac;
 5 long long a[400010];
 6 long long m[300010];
 7 long long ans[200020][3];
 8 int main(){
 9     scanf("%lld%lld",&n,&nq);
10     tail=n;
11     for(register int i=1;i<=n;i++) scanf("%lld",&a[i]),maxx=max(maxx,a[i]);
12     //printf("%lld\n",maxx);
13     for(register int i=2;i<=n;i++){
14         ans[i-1][1]=a[i-1];
15         ans[i-1][2]=a[i];
16         a[++tail]=min(a[i],a[i-1]);
17         a[i]=max(a[i],a[i-1]);
18         if(a[i]==maxx){stop=i;break;}
19     }
20     //for(register int i=1;i<=n;i++) printf("%lld %lld\n",ans[i][1],ans[i][2]);
21     //for(register int i=1;i<=tail;i++) printf("%lld ",a[i]);
22     for(register int i=1;i<=nq;i++){
23         scanf("%lld",&x);
24         if(x<stop) printf("%lld %lld\n",ans[x][1],ans[x][2]);
25         else if(x>=stop){
26             ac=(x-stop)%(n-1)+1;
27             //if(ac==0) ac=n-1;
28             printf("%lld %lld\n",maxx,a[stop+ac]);
29         }
30     }
31     return 0;
32 }
T2-B

 

    T3

  Also thinking questions, more water

  Ideas: light brother every rounds, let's give him a record vis

Later, if the room light brother Charles and Charles's brother before a room adjacent to the light

Then put that room to the side displacement of program do not

  
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 bool ans[100010][4];
 4 bool vis[100010];
 5 int n,m,x;
 6 long long trueans;
 7 int main(){
 8     scanf("%d%d",&n,&m);
 9     trueans=4+3*(n-2);
10     for(register int i=1;i<=m;i++){
11         scanf("%d",&x),vis[x]=1;//2
12         if(vis[x+1]) ans[x+1][1]=1;
13         if(vis[x-1]) ans[x-1][3]=1;
14     }
15     for(register int i=1;i<=n;i++)
16     for(register int j=1;j<=3;j++) if(ans[i][j]) trueans--;
17     for(register int i=1;i<=n;i++) if(vis[i]) trueans--;
18     printf("%lld",trueans);
19     return 0;
20 }
T3-C

    T4

  Puzzles, math problems

  Idea: simultaneously on both sides of the equation we have to take on a [i] -a [j] then the violence to .....

  
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 unsigned long long n,p,k;
 4 unsigned long long a[3000010],b[3000010];
 5 unsigned long long ans,c;
 6 bool vis[3000010];
 7 inline unsigned long long ksc(unsigned long long a,unsigned long long b,unsigned long long p){
 8     unsigned long long ret=0;
 9     while(b){
10         if(b&1) ret=(ret+a)%p;
11         a=(a+a)%p;
12         b>>=1;
13     }
14     return ret;
15 }
16 int main(){
17     scanf("%lld%lld%lld",&n,&p,&k);
18     for(register int i=1;i<=n;i++)
19     {
20         scanf("%lld",&a[i]);
21         a[i]=(a[i]*a[i]%p*a[i]%p*a[i]-k*a[i]%p+p)%p;
22     }
23     sort(a+1,a+n+1);
24     for(int i=1;i<n;i++)
25     {
26         if(a[i]==a[i+1])
27         {
28             c++;
29             
30             ans+=c;
31         }
32         else 
33         c=0;
34         
35     }
36     printf("%lld",ans);
37     return 0;
38 }
T4-D

  For the latter question concerns the metaphysics ~~~

 

  Error 404! ! !

 

  end;

 

 

 

Guess you like

Origin www.cnblogs.com/liuhailin/p/11272314.html