Codeforces Round #252 (Div. 2) C. Valera and Tubes
2014-06-09 01:31
357 查看
<传送门>
【题目大意】
C题:
给你一个一个n行m列的长方形表,相当于一个二维数组,不过是从1开始的,用(x,y)表示一个单元。
现在需要放置k个管道在这些单元中:
1.r>=2;
2.对于各个单元满足:|xi - xi + 1| + |yi - yi + 1| = 1 holds;
3.每个单元只能放一个管道;
如果满足一下条件,则安放管道在该单元:
1.没有一对管道共用一个单元;
2.每一个单元属于一些管道;
请帮助他使用这种方式来将k根管道安排在这个矩形中。
【题目分析】
前k-1步每次走2格,最后一次走完剩下的格子即可,简单的贪心。
View Code
【题目大意】
C题:
给你一个一个n行m列的长方形表,相当于一个二维数组,不过是从1开始的,用(x,y)表示一个单元。
现在需要放置k个管道在这些单元中:
1.r>=2;
2.对于各个单元满足:|xi - xi + 1| + |yi - yi + 1| = 1 holds;
3.每个单元只能放一个管道;
如果满足一下条件,则安放管道在该单元:
1.没有一对管道共用一个单元;
2.每一个单元属于一些管道;
请帮助他使用这种方式来将k根管道安排在这个矩形中。
【题目分析】
前k-1步每次走2格,最后一次走完剩下的格子即可,简单的贪心。
#include <cstdio> #include <iostream> #include <algorithm> #define MAXN 100010 #define ll long long using namespace std; int n, m, k, cnt, col, row; int x[MAXN], y[MAXN]; int main(void) { while(cin >> n >> m >> k) { cnt = 1; x[1] = 1; row = 1; y[1] = 1; col = 1; while(cnt <= n*m) { cnt++; if((col==m&&row%2) || (col==1&&row%2==0)) { row++; x[cnt] = row; y[cnt] = col; } else { if(row % 2) { col++; } else { col--; } x[cnt] = row; y[cnt] = col; } } int j = 1; for(int i=1; i<k; ++i) { cout << "2 " << x[j] << " " << y[j] << " "; ++j; cout << x[j] << " " << y[j] << endl; ++j; } cout << cnt-j << " "; for(int i=j; i<cnt-1; ++i) { cout << x[i] << " " << y[i] << " "; } cout << x[cnt-1] << " " << y[cnt-1] << endl; } return 0; }
View Code
相关文章推荐
- codeforces Round #252 (Div. 2) C - Valera and Tubes
- Codeforces Round #252 (Div. 2) B. Valera and Fruits
- Codeforces Round #252(Div. 2) 441B. Valera and Fruits 贪心
- Codeforces Round #252(Div. 2) 441C. Valera and Tubes 构造
- Codeforces Round #252(Div. 2) 441D. Valera and Swaps 置换群
- Codeforces Round #216_div2_D.Valera and Fools
- Codeforces Round #252 (Div. 2) 441A Valera and Antique Items
- Codeforces Round #252(Div. 2) 441A. Valera and Antique Items 水题
- Codeforces Round #252 (Div. 2)
- Codeforces Round #237 (Div. 2) A. Valera and X(模拟题)
- Codeforces Round #252 (Div. 2) —— B
- Codeforces Round #274 (Div. 2)
- Codeforces Round #425 (Div. 2) D.Misha, Grisha and Underground
- Codeforces Round #410 (Div. 2) D. Mike and distribution(贪心)
- Codeforces Round #212 (Div. 2)
- Codeforces Round #246 (Div. 2)
- Codeforces Round #212 (Div. 2) B. Petya and Staircases
- Codeforces Round #130 (Div. 2) A. Dubstep
- Codeforces Round #394 (Div. 2) A. Dasha and Stairs 水题
- Codeforces Round #460 (Div. 2)-A. Supermarket