这次只做出来两道水题,真是太糟糕了。先挖个坑,到时候再来填吧。
Problem A Sereja and Dima
思路:每次都会从两边去找一个最大的。
代码如下:
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cmath> 5 #include <cstring> 6 #include <algorithm> 7 #include <queue> 8 #include <stack> 9 #include <vector> 10 #define MP(a, b) make_pair(a, b) 11 #define PB(a) push_back(a) 12 13 using namespace std; 14 15 typedef long long ll; 16 typedef pair<int ,int> pii; 17 typedef pair<unsigned int, unsigned int> puu; 18 typedef pair<int ,double> pid; 19 typedef pair<ll, int> pli; 20 21 const int INF = 0x3f3f3f3f; 22 const double eps = 1e-6; 23 24 int main() 25 { 26 // freopen("in.txt", "r", stdin); 27 28 int a, b, s[1111], n; 29 while(scanf("%d", &n)!=EOF){ 30 for(int i=0; i<n; i++){ 31 scanf("%d", &s[i]); 32 } 33 int l = 0, r = n-1; 34 a = b = 0; 35 while(l<=r){ 36 if(s[l]>s[r])a+=s[l++]; 37 else a+=s[r--]; 38 if(l>r) break; 39 if(s[l]>s[r])b+=s[l++]; 40 else b+=s[r--]; 41 } 42 printf("%d %d\n", a, b); 43 } 44 return 0; 45 }
Problem B Sereja and Stairs
思路:只要是次数出现小于3的都能插入进数组里。最后在输出一下注意处理最大的就行了。
代码如下:
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cmath> 5 #include <cstring> 6 #include <algorithm> 7 #include <queue> 8 #include <stack> 9 #include <vector> 10 #define MP(a, b) make_pair(a, b) 11 #define PB(a) push_back(a) 12 13 using namespace std; 14 15 typedef long long ll; 16 typedef pair<int ,int> pii; 17 typedef pair<unsigned int, unsigned int> puu; 18 typedef pair<int ,double> pid; 19 typedef pair<ll, int> pli; 20 21 const int INF = 0x3f3f3f3f; 22 const double eps = 1e-6; 23 const int LEN = 100010; 24 25 int hash[LEN]; 26 27 int main() 28 { 29 // freopen("in.txt", "r", stdin); 30 31 int n; 32 while(scanf("%d", &n)!=EOF){ 33 memset(hash, 0, sizeof hash); 34 int ans = 0; 35 for(int i=0; i<n; i++){ 36 int temp; 37 scanf("%d", &temp); 38 hash[temp]++; 39 if(hash[temp]<3)ans++; 40 } 41 int maxt; 42 for(int i=5000; i>=0; i--){ 43 if(hash[i]){ 44 maxt = i; 45 break; 46 } 47 } 48 if(hash[maxt]>=2)ans--; 49 printf("%d\n", ans); 50 int f = 1; 51 for(int i=0; i<=5000; i++){ 52 if(hash[i]){ 53 if(f==1){printf("%d", i);f=0;} 54 else printf(" %d", i); 55 } 56 } 57 for(int i=5000; i>=0; i--){ 58 if(hash[i]>=2){ 59 if(i==maxt)continue; 60 if(f==1){printf("%d", i);f=0;} 61 else printf(" %d", i); 62 } 63 } 64 printf("\n"); 65 } 66 return 0; 67 }
Codeforces Round #223 (Div. 2) 解题报告
原文:http://www.cnblogs.com/shu-xiaohao/p/3516820.html