Codeforces #298题解

Source: Internet
Author: User

Question A

There are a lot of feasible construction methods that I am taking for each number I and I+N/2 pairing way. For 4 special treatment, for 2 4 1 3.

#include <iostream>#include<string>using namespacestd;intMain () {intN; CIN>>N; if(n==1) {cout<<1<<Endl; cout<<1<<Endl; }    Else if(n==2) {cout<<1<<Endl; cout<<1<<Endl; }        Else if(n==3) {cout<<2<<Endl; cout<<"1 3"<<Endl; }    Else if(n==4) {cout<<4<<Endl; cout<<"2 4 1 3"<<Endl; }    Else    {        if(n%2==0) {cout<<n<<Endl; cout<<1<<" "<<1+n/2;  for(intI=2; i<=n/2; i++) cout<<" "<<i<<" "<<i+n/2; cout<<Endl; }        Else{cout<<n<<Endl;  for(intI=1;i< (n+1)/2; i++) cout<<i<<" "<<i+ (n+1)/2<<" "; cout<< (n+1)/2; cout<<Endl; }    }}

B: For each d>=i>=-d enumeration, fetch can satisfy the maximum value that can be reached in the remaining time v2. That is the greedy law.

#include <iostream>#include<cstdio>#include<algorithm>using namespacestd;intV1,v2;intt,d,sum;intMain () {CIN>>v1>>v2>>t>>D; if(V2 <v1) swap (V1,V2); Sum=v1;  for(intI=2; i<=t;i++)    {         for(intj=d;j>=-d;j--)        {            if(v1+j-(t-i) *d<=v2) {V1+=J;  Break; }} sum+=v1; } cout<<sum<<Endl; return 0;}

C: First to find the upper limit (except yourself, the other is at least 1 o'clock) Max, because the data is 10^5, so pre-processing out sum[i], the first I and. This can be calculated by tot and sum[when each lower limit is taken.

Note the situation of the lower limit temp<0 special treatment.

#include <iostream>#include<cstring>#include<string>#include<cmath>#include<algorithm>using namespacestd;Long Longsum[200004];Long Longs[200004];intMain () {Long LongN,tot; CIN>>n>>tot; Long Longk=tot-(n1); sum[0]=0;  for(Long LongI=1; i<=n;i++) {cin>>S[i]; if(s[i]>=k) Sum[i]=sum[i-1]+K; ElseSum[i]=sum[i-1]+S[i]; }     Long Longfirst=0;  for(Long LongI=1; i<=n;i++)    {       Long Longans=0; if(s[i]>k) Ans+ = (s[i]-k); Long Longtemp=tot-(sum[n]-(sum[i]-sum[i-1])); if(temp-1<=0) Temp=1; Ans+=min (temp-1, S[i]); if(first++) cout<<" "; cout<<ans; } cout<<Endl;}

D: Starting from 0, if the current value is >=3, but not found in the sequence, then only 3, that is, only the number of handshakes +1 and the number of people shaking hands -3 of the two cases. If it is still not found, the output impossible.

#include <iostream>#include<string>#include<queue>using namespaceStd;queue<int> q[200005];intres[200005];intMain () {intN,num; CIN>>N;  for(intI=1; i<=n;i++) {cin>>num;    Q[num].push (i); }    intCur=0;  for(intI=1; i<=n;i++)    {         while(Q[cur].empty () &&cur>=3) cur-=3;  while(Q[cur].empty ()) {cout<<"Impossible"<<Endl; return 0; }        inttemp=Q[cur].front ();        Q[cur].pop (); Res[i]=temp; Cur++; }    intfirst=0; cout<<"Possible"<<Endl;  for(intI=1; i<=n;i++)    {        if(first++) cout<<" "; cout<<Res[i]; } cout<<Endl; }

E: Waiting for updates

Codeforces #298题解

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.