首页 > 其他 > 详细

Codeforces Round #364 (Div. 2)

时间:2016-07-23 11:53:21      阅读:193      评论:0      收藏:0      [点我收藏+]

还是4个1a

记录代码

 

A

技术分享
 1 //#define txtout
 2 //#define debug
 3 #include<bits/stdc++.h>
 4 #define mt(a,b) memset(a,b,sizeof(a))
 5 using namespace std;
 6 typedef long long LL;
 7 const double pi=acos(-1.0);
 8 const double eps=1e-8;
 9 const int inf=0x3f3f3f3f;
10 const int M=1e5+10;
11 int n,m;
12 int a[M];
13 bool v[M];
14 void solve(){
15 
16 }
17 int main(){
18     #ifdef txtout
19     freopen("in.txt","r",stdin);
20     freopen("out.txt","w",stdout);
21     #endif // txtout
22     while(~scanf("%d",&n)){
23         int sum=0;
24         for(int i=1;i<=n;i++){
25             scanf("%d",&a[i]);
26             sum+=a[i];
27             v[i]=false;
28         }
29         int avg=sum*2/n;
30         for(int i=1;i<=n;i++){
31             bool flag=false;
32             for(int j=1;j<=n;j++){
33                 if(v[j]) continue;
34                 for(int k=j+1;k<=n;k++){
35                     if(v[k]) continue;
36                     if(a[j]+a[k]==avg){
37                         flag=true;
38                         printf("%d %d\n",j,k);
39                         v[j]=true;
40                         v[k]=true;
41                         break;
42                     }
43                 }
44                 if(flag) break;
45             }
46         }
47     }
48     return 0;
49 }
View Code

 

 

B

技术分享
 1 //#define txtout
 2 //#define debug
 3 #include<bits/stdc++.h>
 4 #define mt(a,b) memset(a,b,sizeof(a))
 5 using namespace std;
 6 typedef long long LL;
 7 const double pi=acos(-1.0);
 8 const double eps=1e-8;
 9 const int inf=0x3f3f3f3f;
10 const int M=1e5+10;
11 int n,m;
12 set<int> sx,sy;
13 int main(){
14     #ifdef txtout
15     freopen("in.txt","r",stdin);
16     freopen("out.txt","w",stdout);
17     #endif // txtout
18     while(~scanf("%d%d",&n,&m)){
19         sx.clear();
20         sy.clear();
21         LL tn=n;
22         bool flag=false;
23         int x,y;
24         while(m--){
25             scanf("%d%d",&x,&y);
26             sx.insert(x);
27             sy.insert(y);
28             LL sum=0;
29             x=sx.size();
30             y=sy.size();
31             sum=tn*tn-tn*x-tn*y+1LL*x*y;
32             if(flag) putchar( );
33             printf("%I64d",sum);
34             flag=true;
35         }
36         puts("");
37     }
38     return 0;
39 }
View Code

 

 

C

技术分享
 1 //#define txtout
 2 //#define debug
 3 #include<bits/stdc++.h>
 4 #define mt(a,b) memset(a,b,sizeof(a))
 5 using namespace std;
 6 typedef long long LL;
 7 const double pi=acos(-1.0);
 8 const double eps=1e-8;
 9 const int inf=0x3f3f3f3f;
10 const int M=1e5+10;
11 int n;
12 char a[M];
13 int sum[64][M];
14 int toid(char c){
15     if(c>=a&&c<=z) return c-a;
16     return c-A+26;
17 }
18 void init(){
19     for(int i=0;i<52;i++){
20         sum[i][0]=0;
21     }
22     sum[toid(a[0])][0]=1;
23     for(int i=1;i<n;i++){
24         for(int j=0;j<52;j++){
25             sum[j][i]=sum[j][i-1];
26         }
27         sum[toid(a[i])][i]++;
28     }
29 }
30 bool judge(int s,int mid){
31     for(int i=0;i<52;i++){
32         if(sum[i][n-1]==0) continue;
33         int total=sum[i][mid];
34         if(s>0) total-=sum[i][s-1];
35         if(total<=0) return false;
36     }
37     return true;
38 }
39 int bs(int s){
40     int L=s,R=n-1,result=-1;
41     while(L<=R){
42         int mid=(L+R)>>1;
43         if(judge(s,mid)){
44             result=mid;
45             R=mid-1;
46         }
47         else{
48             L=mid+1;
49         }
50     }
51     return result;
52 }
53 int solve(){
54     init();
55     int answer=n;
56     for(int i=0;i<n;i++){
57         int last=bs(i);
58         if(last==-1) break;
59         answer=min(answer,last-i+1);
60     }
61     return answer;
62 }
63 int main(){
64     #ifdef txtout
65     freopen("in.txt","r",stdin);
66     freopen("out.txt","w",stdout);
67     #endif // txtout
68     while(~scanf("%d%s",&n,a)){
69         printf("%d\n",solve());
70     }
71     return 0;
72 }
View Code

 

 

D

技术分享
 1 //#define txtout
 2 //#define debug
 3 #include<bits/stdc++.h>
 4 #define mt(a,b) memset(a,b,sizeof(a))
 5 using namespace std;
 6 typedef long long LL;
 7 const double pi=acos(-1.0);
 8 const double eps=1e-8;
 9 const int inf=0x3f3f3f3f;
10 const int M=1e5+10;
11 int n,l,v1,v2,k;
12 
13 bool judge(double cut_time,double len,int m){
14     #ifdef debug
15     printf("cut_time=%.3f   len=%.3f   m=%d\n",cut_time,len,m);
16     #endif // debug
17     if(m==0) return true;
18 //    if(len<eps) return true;
19     if(v2*cut_time<len) return false;
20     double t1=(len-v2*cut_time)/(v1-v2);
21     double t2=cut_time-t1;
22     double left=len-v1*t2;
23     #ifdef debug
24     printf("t1 = %.3f   t2 = %.3f    left = %.3f\n",t1,t2,left);
25     #endif // debug
26     if(left<eps) return true;
27     double carleft=len-v2*t2;
28     double meettime=(left-carleft)/(v1+v2);
29     left-=v1*meettime;
30     if(left<eps) return true;
31     return judge(t1-meettime,left,m-1);
32 }
33 double solve(){
34     int m=n/k;
35     if(n%k) m++;
36     double L=0,R=l*1.0/v1;
37     double answer=R;
38     int step=100;
39     while(step--){
40         double mid=(L+R)*0.5;
41         #ifdef debug
42         printf("judge\n");
43         #endif // debug
44         if(judge(mid,l,m)){
45             answer=mid;
46             R=mid;
47         }
48         else{
49             L=mid;
50         }
51     }
52     return answer;
53 }
54 int main(){
55     #ifdef txtout
56     freopen("in.txt","r",stdin);
57     freopen("out.txt","w",stdout);
58     #endif // txtout
59     while(~scanf("%d%d%d%d%d",&n,&l,&v1,&v2,&k)){
60         printf("%.10f\n",solve());
61     }
62     return 0;
63 }
View Code

 

 

end

Codeforces Round #364 (Div. 2)

原文:http://www.cnblogs.com/gaolzzxin/p/5698031.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!