您的位置:首页 > 其它

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

2014-02-12 02:34 549 查看
开了个小号去做div2写一下解题报告。

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: