Codeforces Round #224 (Div. 2) 解题报告

Problem A Coder

题意:水题

代码如下:

Codeforces Round #224 (Div. 2) 解题报告
 1 //2014-01-20-23.26
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstdlib>
 5 #include <cmath>
 6 #include <cstring>
 7 #include <algorithm>
 8 #include <queue>
 9 #include <stack>
10 #include <vector>
11 #define MP(a, b) make_pair(a, b)
12 #define PB(a) push_back(a)
13 
14 using namespace std;
15 
16 typedef long long ll;
17 typedef pair<int ,int> pii;
18 typedef pair<unsigned int, unsigned int> puu;
19 typedef pair<int ,double> pid;
20 typedef pair<ll, int> pli;
21 
22 const int INF = 0x3f3f3f3f;
23 const double eps = 1e-6;
24 const int LEN = 1010;
25 int Map[LEN][LEN];
26 int ans;
27 
28 int main()
29 {
30 //    freopen("in.txt", "r", stdin);
31 
32     int n;
33     while(scanf("%d", &n)!=EOF){
34         memset(Map, 0, sizeof Map);
35         ans = 0;
36         for(int i=1; i<=n; i++){
37             int f = i%2;
38             for(int j=1; j<=n; j++){
39                 Map[i][j] = f;
40                 ans += f;
41                 f = !f;
42             }
43         }
44         printf("%d\n", ans);
45         for(int i=1; i<=n; i++){
46             for(int j=1; j<=n; j++){
47                 if(Map[i][j])printf("C");
48                 else printf(".");
49             }printf("\n");
50         }
51         printf("\n");
52     }
53     return 0;
54 }
View Code

Problem B Multitasking

题意:对n个数组排序 每个长度都为n,让你输出一个序列(i,j)当i>j时才交换每个数组中的i,j号元素。

思路:这道题我十分二的,用了冒泡排序还去判断什么的。其实只要不管怎么样都交换m*(m-1)/2次就好了。

二B代码:

Codeforces Round #224 (Div. 2) 解题报告
 1 //2014-01-20-23.26
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstdlib>
 5 #include <cmath>
 6 #include <cstring>
 7 #include <algorithm>
 8 #include <queue>
 9 #include <stack>
10 #include <vector>
11 #define MP(a, b) make_pair(a, b)
12 #define PB(a) push_back(a)
13 
14 using namespace std;
15 
16 typedef long long ll;
17 typedef pair<int ,int> pii;
18 typedef pair<unsigned int, unsigned int> puu;
19 typedef pair<int ,double> pid;
20 typedef pair<ll, int> pli;
21 
22 const int INF = 0x3f3f3f3f;
23 const double eps = 1e-6;
24 const int LEN = 1010;
25 int ary[LEN][LEN], n, m;
26 
27 int main()
28 {
29 //    freopen("in.txt", "r", stdin);
30 
31     int order;
32 
33     while(scanf("%d%d%d", &n, &m, &order)!=EOF){
34         for(int i=0; i<n; i++){
35             for(int j=0; j<m; j++){
36                 scanf("%d", &ary[i][j]);
37             }
38         }
39         int ans = 0;
40         queue<pii> q;
41         for(int i=m-1; i>=0; i--){
42             for(int j=0; j<i; j++){
43                 int f = 0;
44                 for(int k=0; k<n; k++){
45                     if(order){
46                         if(ary[k][j]<ary[k][j+1]){
47                             swap(ary[k][j], ary[k][j+1]);
48                             f = 1;
49                         }
50                     }else {
51                         if(ary[k][j]>ary[k][j+1]){
52                             swap(ary[k][j], ary[k][j+1]);
53                             f = 1;
54                         }
55                     }
56                 }
57                 if(f) {
58                     if(order==0)q.push(MP(j,j+1));
59                     else q.push(MP(j+1,j));
60                 }
61                 ans+=f;
62             }
63         }
64         printf("%d\n", ans);
65         while(!q.empty()){
66             pii nv = q.front(); q.pop();
67             printf("%d %d\n", nv.first+1, nv.second+1);
68         }
69     }
70     return 0;
71 }
View Code

高神的正确姿势:

Codeforces Round #224 (Div. 2) 解题报告
 1 #include <iostream>
 2 #include <sstream>
 3 #include <iomanip>
 4 #include <functional>
 5 #include <algorithm>
 6 #include <vector>
 7 #include <string>
 8 #include <list>
 9 #include <queue>
10 #include <deque>
11 #include <stack>
12 #include <set>
13 #include <map>
14 #include <cstdio>
15 #include <cstdlib>
16 #include <cmath>
17 #include <cstring>
18 #include <climits>
19 using namespace std;
20 #define XINF INT_MAX
21 #define INF 0x3FFFFFFF
22 #define MP(X,Y) make_pair(X,Y)
23 #define PB(X,Y) push_back(X,Y)
24 #define REP(X,N) for(int X=0;X<N;X++)
25 typedef pair<int,int> pii;
26 typedef vector<int> vi;
27 typedef long long ll;
28 
29 
30 int a[1000][100];
31 int main()
32 {
33     int n,m,k;
34     while(cin>>n>>m>>k)
35     {
36         for(int i = 0; i < n; i++)
37         for(int j = 0; j < m; j++)
38             cin>>a[i][j];
39         //if(k==0) //ascending
40         cout<<m*(m-1)/2<<endl;
41         for(int i = 0; i < m; i++)
42         for(int j = 0; j < m-i-1; j++)
43         {
44             if(k==0)
45                 cout<<j+1<< <<j+2<<endl;
46             else
47                 cout<<j+2<< <<j+1<<endl;
48         }
49     }
50     return 0;
51 }
View Code

Problem C Milking cows

题意:一列牛1为头向右看的0为头向左看的。在一个牛被喂奶的时候有没喂过奶的牛看见会浪费一单元奶。问最少浪费多少单元奶?

思路:贪心先把朝一个方向的牛喂光,这样剩下来的就没有花费了。

代码如下:

Codeforces Round #224 (Div. 2) 解题报告
 1 //2014-01-20-23.26
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <algorithm>
 6 #include <queue>
 7 #include <stack>
 8 #include <vector>
 9 #define MP(a, b) make_pair(a, b)
10 #define PB(a) push_back(a)
11 
12 using namespace std;
13 
14 typedef long long ll;
15 typedef pair<int ,int> pii;
16 typedef pair<unsigned int, unsigned int> puu;
17 typedef pair<int ,double> pid;
18 typedef pair<ll, int> pli;
19 
20 const int INF = 0x3f3f3f3f;
21 const double eps = 1e-6;
22 const int LEN = 201010;
23 
24 int main()
25 {
26 //    freopen("in.txt", "r", stdin);
27 
28     int n, tt;
29     ll sum, ans;
30     while(scanf("%d",&n)!=EOF){
31         ans = sum = 0;
32         for(int i=1; i<=n; i++){
33             scanf("%d", &tt);
34             if(tt)sum += tt;
35             else ans+=sum;
36         }
37         printf("%I64d\n", ans);
38     }
39     return 0;
40 }
View Code

Codeforces Round #224 (Div. 2) 解题报告

上一篇:数组排序方法


下一篇:Photoshop CS3制作动画:设定帧过渡