Codeforces Round #355 (Div. 2)

A

弯腰

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<queue>
 5 #include<stack>
 6 #include<algorithm>
 7 using namespace std;
 8 #define clc(a,b) memset(a,b,sizeof(a))
 9 #define inf 0x3f3f3f3f
10 const int N=10010;
11 #define LL long long
12 // inline int r(){
13 //     int x=0,f=1;char ch=getchar();
14 //     while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
15 //     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
16 //     return x*f;
17 // }
18 
19 int main(){
20     int n,m;
21     int ans=0;
22     scanf("%d%d",&n,&m);
23     for(int i=0;i<n;i++){
24        int x;
25        cin>>x;
26        if(x<=m)
27         ans+=1;
28        else
29         ans+=2;
30     }
31     cout<<ans<<endl;
32     return 0;
33 }

B

处理器一秒能处理k个东西,缓冲区最多不能超过h个,问几秒处理完

模拟,注意h很大,k很小的情况!!所以必须用除法避免超时

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<queue>
 5 #include<stack>
 6 #include<algorithm>
 7 using namespace std;
 8 #define clc(a,b) memset(a,b,sizeof(a))
 9 #define inf 0x3f3f3f3f
10 const int N=10010;
11 #define LL long long
12 void fre(){freopen("in.txt","r",stdin); }
13 // inline int r(){
14 //     int x=0,f=1;char ch=getchar();
15 //     while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
16 //     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
17 //     return x*f;
18 // }
19 int a[100010];
20 
21 int main(){
22     // fre();
23     int n,h,k;
24     cin>>n>>h>>k;
25     for(int i=1;i<=n;i++){
26        scanf("%d",&a[i]);
27     }
28     LL sum=0;
29     LL ans=0;
30     for(int i=1;i<=n;i++){
31        sum+=a[i];
32        while(sum+a[i+1]<=h){
33           sum+=a[i+1];
34           i++;
35           if(i>n)
36             break;
37        }
38        // cout<<i<<" "<<sum<<endl;
39        while(1){
40           int tem=sum;
41           sum%=k;
42           ans+=tem/k;
43           if(sum<=0)
44           {
45             sum=0;
46             break;
47           }
48           if(i<n){
49             if(sum+a[i+1]<=h)
50                break;
51           } 
52           if(sum<k&&sum>0){
53              sum=0;
54              ans++;
55              // cout<<sum<<" "<<ans<<endl;
56              break;
57           }
58        }
59        // cout<<i<<" "<<sum<<endl;
60     }
61     cout<<ans<<endl;
62     return 0;
63 }

C

统计每个字符对应的数字有几个0,答案就是pow(3,n)。二进制是六位

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<queue>
 5 #include<stack>
 6 #include<algorithm>
 7 using namespace std;
 8 #define clc(a,b) memset(a,b,sizeof(a))
 9 #define inf 0x3f3f3f3f
10 const int N=10010;
11 const int MOD = 1e9+7;
12 #define LL long long
13 void fre(){freopen("in.txt","r",stdin); }
14 // inline int r(){
15 //     int x=0,f=1;char ch=getchar();
16 //     while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
17 //     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
18 //     return x*f;
19 // }
20 LL pow_m(LL a,LL b)  
21 {  
22     LL ans = 1;  
23     a %= MOD;  
24 while(b) 
25 {  
26         if(b & 1)  
27         {  
28             ans = ans * a % MOD;  
29             b--;  
30         }  
31         b >>= 1;  
32         a = a * a % MOD;  
33     }  
34     return ans;  
35 }  
36 
37 int fun(int x){
38     int num=0;
39     int cnt=6;
40     while(cnt){
41        if((x&1)==0)
42           num++;
43        x>>=1;
44        cnt--;
45     }
46     return num;
47 }
48 string s;
49 bool vis[100];
50 int main(){
51     // freopen("in.txt","r",stdin);
52     getline(cin,s);
53     LL num=0;
54     LL ans=0;
55     clc(vis,false);
56     for(int i=0;i<s.length();i++){
57         int x;
58         if(s[i]>='0'&&s[i]<='9'){
59            x=s[i]-'0';
60            num+=fun(x);
61         }
62         else if(s[i]>='A'&&s[i]<='Z'){
63            x=s[i]-'A'+10;
64            num+=fun(x);
65         }
66         else if(s[i]>='a'&&s[i]<='z'){
67             x=s[i]-'a'+36;
68             num+=fun(x);
69         }
70         else if(s[i]=='-'){
71            num+=fun(62);
72         }
73         else{
74            num+=fun(63);
75         }
76     }
77     // cout<<num<<endl;
78     ans=pow_m(3,num);
79     printf("%I64d
",ans);
80     return 0;
81 }
原文地址:https://www.cnblogs.com/ITUPC/p/5554870.html