SGU 109 Magic of David Copperfield II
来源:互联网 发布:网络教育学生能当兵吗 编辑:程序博客网 时间:2024/05/21 15:00
构造策略:
先走n步 把大于与左上角曼哈顿距离的格子删掉 因为这些格子是达不到的(曼哈顿距离:横坐标之差+纵坐标之差)然后就要处理奇偶性了:如果为偶数,则+1,转换为奇数;否则+2。设一个dist为每次的曼哈顿距离与当前点的差。一层一层向里删除格子,知道这个差dist<=2,游戏结束,玩家已经被困在中间格子内。
AC代码:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>int n;int main(){ scanf("%d",&n); printf("%d",n); for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (i-1+j-1>n) printf(" %d",(i-1)*n+j); printf("\n"); int dist = n+2; int now = n; while (dist > 2){ now++; while (now % 2 == 0) now++; printf("%d",now); for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (i+j == dist) printf(" %d",(i-1)*n+j); printf("\n"); dist--; } //system("pause"); return 0;}
0 0
- SGU 109 Magic of David Copperfield II
- sgu 109 Magic of David Copperfield II
- SGU 109 Magic of David Copperfield II
- SGU 109 Magic of David Copperfield II
- [SGU]109. Magic of David Copperfield II
- SGU 109 Magic of David Copperfield II 奇偶性
- SGU 109 Magic of David Copperfield II(构造)
- SGU 109 Magic of David Copperfield II(构造)
- 【SGU】109. Magic of David Copperfield II 构造
- sgu109 Magic of David Copperfield II 构造
- sgu109:Magic of David Copperfield II
- 109. Magic of David Copperfield II
- SGU109 Magic of David Copperfield II
- uva 769 - Magic of David Copperfield(构造)
- UVA - 769 Magic of David Copperfield
- UVA - 769 Magic of David Copperfield 构造
- UVA 769 - Magic of David Copperfield(构造问题)
- UVa 769 - Magic of David Copperfield 解题报告(思维)
- SDK Manager不能启动之android.bat和monitor.bat配置
- python int与ip互转
- nyoj540奇怪的排序
- 深入理解ORACLE并行
- Platform Builder: Sources Files 2
- SGU 109 Magic of David Copperfield II
- 数据流图笔记
- Implement strStr()
- css-之div一行排列
- C#中的数据类型
- Java跨平台原因
- parallel_index并发
- Struts2+Json+Ajax+FusionChart支持Iphone、ipad、mac的3D图形Demo,部署即可使用。
- 设计模式----装饰模式