Codeforces Round #229 (Div. 2) 解题报告
2014-02-12 02:34
549 查看
开了个小号去做div2写一下解题报告。
Problem A Inna and Alarm Clock
简单题。直接开数组标记一下即可。代码如下:
View Code
Problem A Inna and Alarm Clock
简单题。直接开数组标记一下即可。代码如下:
/************************************************** * Author : xiaohao Z * Blog : http://www.cnblogs.com/shu-xiaohao/ * Last modified : 2014-02-11 23:29 * Filename : Round_229_2_D.cpp * Description : * ************************************************/ #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <algorithm> #include <queue> #include <stack> #include <vector> #include <set> #include <map> #define MP(a, b) make_pair(a, b) #define PB(a) push_back(a) using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<unsigned int,unsigned int> puu; typedef pair<int, double> pid; typedef pair<ll, int> pli; typedef pair<int, ll> pil; const int INF = 0x3f3f3f3f; const double eps = 1E-6; const int LEN = 55; int Map[LEN][LEN], n, m; struct P{int x, y;}; struct cmp{ bool operator() (P a, P b){ if(a.x+a.y!=b.x+b.y) return a.x+a.y < b.x+b.y; else return a.x > b.x; } }; priority_queue<P, vector<P>, cmp> pq; P MPP(int a, int b){ P ret; ret.x = a; ret.y = b; return ret; } int xx[] = {0, 0, 1,-1}; int yy[] = {1,-1, 0, 0}; int put(int num){ int ret = 1; queue<pii> q; q.push(MP(0,0)); Map[0][0] = 1; pq.push(MPP(0,0)); num--; if(num == 0) return ret; while(!q.empty()){ pii nv = q.front(); q.pop(); for(int i=0; i<4; i++){ int tx = nv.first+xx[i]; int ty = nv.second+yy[i]; if(tx >= 0 && tx < n && ty >= 0 && ty < m && !Map[tx][ty]){ Map[tx][ty] = 1; q.push(MP(tx, ty)); pq.push(MPP(tx, ty)); num--; ret += (tx+ty+1); if(num == 0) return ret; } } } } int main() { // freopen("in.txt", "r", stdin); int st; while(scanf("%d%d%d", &n, &m, &st)!=EOF){ memset(Map, 0, sizeof Map); while(!pq.empty())pq.pop(); int ans = put(st); printf("%d\n", ans); while(!pq.empty()){ P nv = pq.top();pq.pop(); nv.x++,nv.y++; int x = 1, y = 1; while(1){ if(x == nv.x && y == nv.y){ printf("(%d,%d)\n", nv.x, nv.y); break; } printf("(%d,%d) ", x, y); if(x < nv.x) x++; else if(y < nv.y) y++; } } } return 0; }
View Code
相关文章推荐
- Codeforces Round #345 (Div. 2) 解题报告
- codeforces round 201 div2解题报告
- Codeforces Round #306 (Div. 2) D.E. 解题报告
- codeforces Round #272(div2) A解题报告
- Codeforces Round #213 (Div. 2) 解题报告
- Codeforces Round #298 (Div. 2) 解题报告 (ABCD)
- Codeforces Round #283 (Div. 1)解题报告A.B.C.
- Codeforces Round #339 (Div. 2) 解题报告
- Codeforces Round #291 (Div. 2) 解题报告 (A B C D)
- Codeforces Round #277.5 (Div. 2) 解题报告(A B C D)
- Codeforces Round #239 (Div. 1) 解题报告
- Codeforces Round #188 (Div. 2) 解题报告 //缺E
- Codeforces Round #284 (Div. 2) C. Crazy Town ACM解题报告(几何)
- codeforces Round #272(div2) B解题报告
- Codeforces Round #274 (Div. 2) 解题报告 (C D E)
- Codeforces Round #191 (Div. 2) 解题报告
- Codeforces Round #188 (Div. 2) 解题报告 //缺E
- Codeforces Round #266 (Div. 2)(解题报告)
- Codeforces Round #267 (Div. 2) 解题报告
- codeforces Round #272(div2) C解题报告