1. 程式人生 > >[Codeforces] Round #436 (Div. 2)

[Codeforces] Round #436 (Div. 2)

stack turn hid show lag close none scanf buck

技術分享
 1 #include<cstdio>
 2 #include<iostream>
 3 using namespace std;
 4 
 5 int n,cnt,ans,A,B;
 6 int buck[500];
 7 
 8 int main(){
 9     scanf("%d",&n);
10     
11     for(int i = 1;i <= n;i++){
12         cin >> cnt;
13         if(!buck[cnt]){
14             ans++;
15 if(A) B = cnt; 16 else A = cnt; 17 } 18 buck[cnt]++; 19 } 20 21 if(ans == 2 && buck[A] == buck[B]) printf("YES\n%d %d",A,B); 22 else printf("NO"); 23 24 return 0; 25 }
A 技術分享
 1 #include<cstdio>
 2 #include<iostream>
 3
#include<bitset> 4 using namespace std; 5 6 bitset<100> buck; 7 char ctr; 8 int ans,n; 9 10 int main(){ 11 scanf("%d",&n); 12 13 for(int i = 1;i <= n;i++){ 14 cin >> ctr; 15 if(ctr <= Z && ctr >= A){ 16 ans = max(ans,(int
)buck.count()); 17 buck.reset(); 18 }else{ 19 buck.set((int)(ctr-a)); 20 } 21 } 22 23 ans = max(ans,(int)buck.count()); 24 25 printf("%d",ans); 26 27 return 0; 28 }
B 技術分享
 1 #include<cstdio>
 2 #include<iostream>
 3 using namespace std;
 4 
 5 int a,b,f,k,ans,tank;
 6 
 7 int main(){
 8     scanf("%d%d%d%d",&a,&b,&f,&k);
 9     
10     tank = b;
11     
12     for(int i = 1;i <= k;i++){
13         if(i%2){ //0 -> a
14             if(tank < f){ printf("-1"); return 0; }
15             
16             tank -= f;
17             
18             // Refruel
19             if(tank < ((i < k)?(2*(a-f)):(a-f))){
20 //                printf("#%d: %d\n",k,tank);
21                 tank = b,ans++;
22             }
23             
24             
25             
26             // Can‘t arr
27             if(tank < (a-f)){ printf("-1"); return 0; }
28             
29             tank -= (a-f);
30         }else{   //a -> 0
31             // Can‘t refruel?
32             if(tank < (a-f)){ printf("-1"); return 0; }
33 //            
34             tank -= (a-f);
35             
36             if(tank < ((i < k)?(2*f):(f))){
37 //                printf("#%d: %d\n",k,tank);
38                 tank = b,ans++;
39             }
40             
41             if(tank < f){ printf("-1"); return 0; }
42             
43             tank -= f;
44         }
45     }
46     
47     printf("%d",ans);
48     
49     return 0;
50 }
C 技術分享
 1 #include<cstdio>
 2 #include<iostream>
 3 #include<bitset>
 4 #include<queue>
 5 using namespace std;
 6 
 7 bool flag[202020];
 8 int n,cnt,buc[202020],arr[202020],ans;
 9 bitset<202020> buck;
10 queue<int> Q;
11 
12 int main(){
13     scanf("%d",&n);
14     
15     for(int i = 1;i <= n;i++){
16         scanf("%d",&cnt);
17         buc[cnt]++;
18         arr[i] = cnt;
19         buck.set(cnt);
20     }
21     
22     if(buck.count() == n){
23         printf("0\n");
24         for(int i = 1;i <= n;i++)
25             printf("%d ",arr[i]);
26         return 0;
27     }
28     
29     for(int i = 1;i <= n;i++){
30         if(!buc[i]) Q.push(i);
31     }
32     
33     for(int i = 1;i <= n;i++){
34         if(buc[arr[i]] > 1 && (arr[i] > Q.front() || flag[arr[i]])){
35             ans++;
36             buc[arr[i]]--;
37             arr[i] = Q.front();
38             Q.pop();
39         }else if(buc[arr[i]] > 1) flag[arr[i]] = true;
40     }
41     
42     printf("%d\n",ans);
43     for(int i = 1;i <= n;i++){
44         printf("%d ",arr[i]);
45     }
46     
47     return 0;
48 }
D 技術分享
 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<iostream>
 4 #define maxn 3000
 5 using namespace std;
 6 
 7 int n,Poi,sPoi,con[maxn],last[maxn][maxn],obj[maxn],DP[maxn];
 8 int stack[maxn],maxline;
 9 
10 struct item{
11     int ord,d,t,p;
12 }arr[2000];
13 
14 bool cmp(const item &a,const item &b){
15     return a.d < b.d;
16 }
17 
18 int main(){
19     scanf("%d",&n);
20     
21     for(int i = 1;i <= n;i++){
22         int d,t,p;
23         scanf("%d%d%d",&t,&d,&p);
24         arr[i].t = t;
25         arr[i].d = d;
26         maxline = max(maxline,d);
27         arr[i].p = p;
28         arr[i].ord = i;
29     }
30     
31     sort(arr+1,arr+1+n,cmp);
32     
33     for(int i = 1;i <= n;i++){
34 //        for(int j = 1;j <= maxline;j++) last[i][j] = 0;
35         for(int j = arr[i].d-1;j >= arr[i].t;j--){
36             if(DP[j] < DP[j-arr[i].t]+arr[i].p){
37                 DP[j] = DP[j-arr[i].t]+arr[i].p;
38                 con[j] = con[j-arr[i].t]+1;
39                 last[i][j] = 1; // Means that: At i-Decide j-Item was chosen
40                 obj[j] = i;
41             }
42         }
43     }
44     
45     int ans = -1,id = 0;
46     for(int j = 0;j <= 2000;j++){
47         if(ans<DP[j]){
48             ans = DP[j];
49             id = j;
50         }
51     }
52     
53     for(int i = n;i >= 1;i--){
54         if(last[i][id]){
55             id -= arr[i].t;
56             stack[sPoi++] = arr[i].ord;
57         }
58     }
59     
60     printf("%d\n%d\n",ans,sPoi);
61     
62     for(int i = sPoi-1;i >= 0;i--) printf("%d ",stack[i]);
63     
64     return 0;
65 }
E

第二天再來寫詳細= =

學了好多,,,

[Codeforces] Round #436 (Div. 2)