UVA10161-棋盘上的蚂蚁
来源:互联网 发布:东莞制造业 数据 编辑:程序博客网 时间:2024/04/29 04:10
碰见这个蚂蚁棋盘问题。我开始的时候是纯手工模拟
,交上后严重超时
,交上后严重超时
代码见;
#include <iostream>using namespace std;struct point{ int i , j;};void returnij(int step){ point p; p.i = 1; p.j = 1; int ceng = 1; int xu = 1; while(xu<step) { if(step==1) { break; } if(xu<step) { if(ceng%2) { p.i++; xu++; if(xu==step)break; } else { p.j++; xu++; if(xu==step)break; } } int temp = ceng; while(temp--&&xu<step) { if(ceng%2) { p.j++; xu++; if(xu==step)break; } else { p.i++; xu++; if(xu==step)break; } } temp = ceng; while(temp--&&xu<step) { if(ceng%2) { p.i--; xu++; if(xu==step)break; } else { p.j--; xu++; if(xu==step)break; } } ceng++; } cout<<p.j<<" "<<p.i<<endl;}int main (){ int n; while(cin>>n) { if(!n)break; returnij(n); } return 0;}
后来看了人家的解题报告后,我才知道了其中的规律
根据数学规律做题,完全不存在效率问题
但是我进来好像养成了看人家解题报告的习惯
这是十分危险的
有许多的前车之鉴,
以后还需克服!!!!
#include <iostream>using namespace std;int main (){ int n; while(cin>>n) { if(!n)break; int x, y; int k = 0; for(k = 0; k * k < n; k++); int a = (k-1)*(k-1); int b = n - a; if(k&1) { if(b<=k) { x = k; y = b; } else { y = k; x = 2 * k - b; } } else { if(b<=k) { y = k; x = b; } else { x = k; y = 2 * k - b; } } cout<<x<<" "<<y<<endl; }}
- UVA10161-棋盘上的蚂蚁
- UVA 10161 棋盘上的蚂蚁
- uva 10161-棋盘上的蚂蚁
- UVa 10161 棋盘上的蚂蚁
- UVa 10161 棋盘上的蚂蚁
- UVa_OJ 10161 棋盘上的蚂蚁
- UVa Problem 10161 Ant on a Chessboard (棋盘上的蚂蚁)
- uva10161
- 木杆上的蚂蚁
- 木棒上的蚂蚁
- 棋盘上的距离
- 棋盘上的麦子
- 棋盘上的距离
- 棋盘上的距离
- 棋盘上的距离
- 棋盘上的守卫
- 棋盘上的距离
- 解答:木杆上的蚂蚁
- Qt中文显示
- asp.net 加页面Loading效果
- poj 1655 Balancing Act
- UVA10152-龟壳排序
- 悟透JavaScript之回归简单
- UVA10161-棋盘上的蚂蚁
- MyEclipse8.6 自带辅助替代spket插件,javascript 代码自动完成
- linux设备驱动开发环境搭建
- DllMain
- 悟透JavaScript之回归简单 -- 2
- 与或逻辑运算的实现及格式验证
- DLL笔记
- C++学习之类
- UVA10177-2/3/4维方体,立方体