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

回归了回归了!考试周终于过去了。博客也该更新了

Problem A Valera and X

题意:让你判断一个字符方阵是不是x。

思路:很好办暴力就行了不多说了。

代码如下:

 1 /**************************************************
 2  * Author     : xiaohao Z
 3  * Blog     : http://www.cnblogs.com/shu-xiaohao/
 4  * Last modified : 2014-03-19 23:22
 5  * Filename     : Codeforce_237_2_A.cpp
 6  * Description     : 
 7  * ************************************************/
 8 
 9 #include <iostream>
10 #include <cstdio>
11 #include <cstring>
12 #include <cstdlib>
13 #include <cmath>
14 #include <algorithm>
15 #include <queue>
16 #include <stack>
17 #include <vector>
18 #include <set>
19 #include <map>
20 #define MP(a, b) make_pair(a, b)
21 #define PB(a) push_back(a)
22 
23 using namespace std;
24 typedef long long ll;
25 typedef pair<int, int> pii;
26 typedef pair<unsigned int,unsigned int> puu;
27 typedef pair<int, double> pid;
28 typedef pair<ll, int> pli;
29 typedef pair<int, ll> pil;
30 
31 const int INF = 0x3f3f3f3f;
32 const double eps = 1E-6;
33 const int LEN = 1010;
34 char Map[LEN][LEN];
35 int vis[LEN][LEN];
36 
37 int main()
38 {
39 //    freopen("in.txt", "r", stdin);
40 
41     int n;
42     while(cin >> n){
43         memset(vis, 0, sizeof vis);
44         for(int i=0; i<n; i++){
45             for(int j=0; j<n; j++){
46                 cin >> Map[i][j];
47             }
48         }
49         char tmp = Map[0][0];
50         int f = 1;
51         for(int i=0; i<n; i++){
52             vis[i][i] = vis[i][n-i-1] = 1;
53             if(Map[i][i] != tmp) f = 0;
54             if(Map[i][n-i-1] != tmp) f = 0;
55             if(!f) break;
56         }
57         if(Map[0][1] == tmp) f = 0;
58         tmp = Map[0][1];
59         for(int i=0; i<n; i++){
60             for(int j=0; j<n; j++){
61                 if(!vis[i][j] && Map[i][j] != tmp)  f = 0;
62             }
63         }
64         if(f) cout << "YES" << endl;
65         else cout << "NO" << endl;
66     }    
67     return 0;
68 }
View Code

Problem B Marathon

题意:一个坐标轴上一个正方形,右下角为原点,一个人沿着正方形逆时针跑。没跑k距离要喝水,一共和n次,让你输出吗,每次喝水人的坐标。

思路:先摸一下圈长,然后再分四条边讨论。注意这里由于是浮点数所以不能直接模,必须转换一下。注意用longlong就行。

代码如下:

 1 /**************************************************
 2  * Author     : xiaohao Z
 3  * Blog     : http://www.cnblogs.com/shu-xiaohao/
 4  * Last modified : 2014-03-19 23:22
 5  * Filename     : Codeforce_237_2_B.cpp
 6  * Description     : 
 7  * ************************************************/
 8 
 9 #include <iostream>
10 #include <cstdio>
11 #include <cstring>
12 #include <cstdlib>
13 #include <cmath>
14 #include <algorithm>
15 #include <queue>
16 #include <stack>
17 #include <vector>
18 #include <set>
19 #include <map>
20 #define MP(a, b) make_pair(a, b)
21 #define PB(a) push_back(a)
22 
23 using namespace std;
24 typedef long long ll;
25 typedef pair<int, int> pii;
26 typedef pair<unsigned int,unsigned int> puu;
27 typedef pair<int, double> pid;
28 typedef pair<ll, int> pli;
29 typedef pair<int, ll> pil;
30 
31 const int INF = 0x3f3f3f3f;
32 const double eps = 1E-6;
33 double n, k;
34 
35 int calc(double num){
36     num -= ((ll)(num/(4*n))*4*n);
37     return int(num/n);    
38 }
39 
40 int main()
41 {
42 //    freopen("in.txt", "r", stdin);
43 
44     double t;
45     while(scanf("%lf%lf", &n, &k)!=EOF){
46         scanf("%lf", &t);
47         double st = 0;
48         for(int i=1; i<=t; i++){
49             int tag = calc(i*k);
50             double x = (i*k) - ((ll)((i*k)/n)*n);
51             if(tag == 0) printf("%lf %lf
", x, 0.0);
52             else if(tag == 1) printf("%lf %lf
", n, x);
53             else if(tag == 2) printf("%lf %lf
", n-x, n);
54             else printf("%lf %lf
", 0.0, n-x);
55         }
56     }
57     return 0;
58 }
View Code

Problem C Restore Graph

题意:告诉你图上的定点数,每个点上最大边数,已经选定的点到所有点的最短路(选定的点不知道)。让你构造这幅图。不可能输出-1.

思路:我是按照树的形式来构造的首先距离0的点为根(超过一个则不可能)然后1的点为0的点的孩子以此类推。。。由于每个点(除根之外)只能有k-1个孩子。所以每次判断一下即可。

代码如下:

 1 /**************************************************
 2  * Author     : xiaohao Z
 3  * Blog     : http://www.cnblogs.com/shu-xiaohao/
 4  * Last modified : 2014-03-19 23:22
 5  * Filename     : Codeforce_237_2_C.cpp
 6  * Description     : 
 7  * ************************************************/
 8 
 9 #include <iostream>
10 #include <cstdio>
11 #include <cstring>
12 #include <cstdlib>
13 #include <cmath>
14 #include <algorithm>
15 #include <queue>
16 #include <stack>
17 #include <vector>
18 #include <set>
19 #include <map>
20 #define MP(a, b) make_pair(a, b)
21 #define PB(a) push_back(a)
22 
23 using namespace std;
24 typedef long long ll;
25 typedef pair<int, int> pii;
26 typedef pair<unsigned int,unsigned int> puu;
27 typedef pair<int, double> pid;
28 typedef pair<ll, int> pli;
29 typedef pair<int, ll> pil;
30 
31 const int INF = 0x3f3f3f3f;
32 const double eps = 1E-6;
33 const int LEN = 100000+10;
34 int k, n, d[LEN], top;
35 vector<int> Map[LEN];
36 
37 int main()
38 {
39 //    freopen("in.txt", "r", stdin);
40 
41     while(scanf("%d%d", &n, &k)!=EOF){
42         queue<pii> q;
43         while(!q.empty())q.pop();
44         for(int i=0; i<LEN; i++) Map[i].clear();
45         top = 0;
46         for(int i=0; i<n; i++){
47             scanf("%d", &d[i]);
48             Map[d[i]].PB(i);
49             top = max(top, d[i]);
50         }
51         int ans = 1;
52         if(Map[0].size() != 1) ans = 0;
53         else{
54             for(int i=1; i<=top; i++){
55                 if(Map[i].size() == 0) ans = 0;
56             }
57             for(int i=1; i<=top; i++){
58                 int tp = 0, cnt = 0;
59                 if(i==1) cnt--;
60                 for(int j=0; j<Map[i].size(); j++){
61                     q.push(MP(Map[i-1][tp]+1, Map[i][j]+1));            
62                     cnt++;
63                     if(cnt > k-1) {
64                         ans = 0;
65                         break;        
66                     }
67                     else if(cnt == k-1){
68                         cnt = 0;
69                         tp ++;
70                         if(tp == Map[i-1].size() && j!=Map[i].size()-1){
71                             ans = 0;
72                             break;    
73                         }    
74                     }
75                 }
76                 if(!ans) break;
77             }
78         }
79         if(!ans) printf("-1
");
80         else{
81             printf("%d
", q.size());
82             while(!q.empty()){
83                 pii tmp = q.front();q.pop();
84                 printf("%d %d
", tmp.first, tmp.second);
85             } 
86         }
87     }
88     return 0;
89 }
View Code
奔跑吧!少年!趁着你还年轻
原文地址:https://www.cnblogs.com/shu-xiaohao/p/3612779.html