URAL - 1920 Titan Ruins: the Infinite Power of Magic(乱搞)
搞死人的题目,,,
就是在n*n的方格中找路径长度为L的回路。
开始的思路值适合n为偶数的情况,而忽视了奇数的case,所以wa了一次。
然后找奇数case的策略,代码从70多行变成了100多,然后改了又改,自己在下面测了好久,交上去1y,但心里却无成就感。
这样的一个题目,提不上什么思路,可以算作是乱搞的,下次比赛中再次碰到类似甚至同样的题目,我并不能保证能写出来。
代码如下:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <algorithm> #define M 1005 using namespace std; int n, l, maxx; int main ()
{
scanf("%d%d",&n, &l);
if(l&1||n*n<l) printf("Unsuitable device\n");
else
{
printf("Overwhelming power of magic\n");
int c = l/(2*n);
int last = l%(2*n);
printf("1 1\n");
if(l<2*n)
{
int m = last/2;
for(int i = 2; i <= m; ++i)
printf("%d %d\n",2*c+1,i);
for(int i = m; i >= 2; --i)
printf("%d %d\n",2*c+2,i);
printf("2 1\n");
}
else if(n&1)
{
maxx = 2*c;
if(last==0)
{
for(int i = 1; i <= 2*c; ++i)
{
if(i&1)
for(int j = 2; j <= n; ++j)
printf("%d %d\n",i,j);
else
for(int j = n; j >= 2; --j)
printf("%d %d\n",i,j);
}
}
else
{
for(int i = 1; i < 2*c; ++i)
{
if(i&1)
for(int j = 2; j <= n; ++j)
printf("%d %d\n",i,j);
else
for(int j = n; j >= 2; --j)
printf("%d %d\n",i,j);
}
int nn = n-2*c;
int cc = last/(2*nn);
int ll = last%(2*nn);
int mm = n-2*cc;
for(int i = n; i > n-2*cc; --i)
{
if(i&1)
for(int j = 2*c; j <= n; ++j)
printf("%d %d\n",j,i);
else
for(int j = n; j >= 2*c; --j)
printf("%d %d\n",j,i);
}
if(ll==0)
{
for(int i = mm; i >= 2; --i)
printf("%d %d\n",2*c,i);
}
else
{
int tm = ll/2;
for(int i = 2*c; i <= 2*c+tm; ++i)
printf("%d %d\n",i,mm);
for(int i = 2*c+tm; i >= 2*c; --i)
printf("%d %d\n",i,mm-1);
mm-=2;
for(int i = mm; i >= 2; --i)
printf("%d %d\n",2*c,i);
}
}
for(int i = maxx; i >= 2; --i)
printf("%d 1\n",i);
}
else
{
for(int i = 1; i <= 2*c; ++i)
{
if(i&1)
for(int j = 2; j <= n; ++j)
printf("%d %d\n",i,j);
else
for(int j = n; j >= 2; --j)
printf("%d %d\n",i,j);
}
if(last == 0)
maxx = 2*c;
else if(last == 2)
{
printf("%d %d\n",2*c+1,2);
maxx = 2*c+1;
}
else
{
int m = last/2;
maxx = 2*c+2;
for(int i = 2; i <= m; ++i)
printf("%d %d\n",2*c+1,i);
for(int i = m; i >= 2; --i)
printf("%d %d\n",2*c+2,i);
}
for(int i = maxx; i >= 2; --i)
printf("%d 1\n",i);
}
}
return 0;
}
URAL - 1920 Titan Ruins: the Infinite Power of Magic(乱搞)的更多相关文章
- URAL 1920 Titan Ruins: the Infinite Power of Magic
大意: 有一张N*N的网格,你每次可以走一步,每格只能走一次,有没有一种方法让走了L步后回到一个距原点1步远的格子? 没有输出Unsuitable device,否则输出Overwhelming p ...
- URAL - 1917 Titan Ruins: Deadly Accuracy(水题)
水题一个,代码挫了一下: 题意不好理解. 你去一个洞窟内探险,洞窟内有许多宝石,但都有魔法守护,你需要用魔法将它们打下来. 每个宝石都有自己的防御等级,当你的魔法超过它的防御等级时它就会被你打下来. ...
- URAL 1915 Titan Ruins: Reconstruction of Bygones(思路)
搞这个题差不多是从比赛开始到结束. 从自信慢慢的看题一直到wrong到死. 这个题目可以说成是思路题,以为我们只要明白一点,这道题就成了纯暴力的水题, 那就是当操作数不足栈中数字数目的时候,我们就没有 ...
- 【URAL 1917】Titan Ruins: Deadly Accuracy(DP)
题目 #include<cstdio> #include<algorithm> using namespace std; #define N 1005 int n, m, cn ...
- URAL 1827 Indigenous Wars(排序、乱搞)
题意:给一个长度为n数组{a[i]}.有m个操作Ti,Si,Li表示找以Ti值结束,以Si值开始,长度为Li的连续子串.找到后,将区间的答案值设为1.一开始答案值全部为0.最后输出n个答案值. 好久没 ...
- Ural 1780 Gray Code 乱搞暴力
原题链接:http://acm.timus.ru/problem.aspx?space=1&num=1780 1780. Gray Code Time limit: 0.5 secondMem ...
- [USACO2002][poj1945]Power Hungry Cows(启发式搜索)
Power Hungry CowsTime Limit: 1000MS Memory Limit: 30000K Total Submissions: 4570 Accepted: 1120 Desc ...
- 2016中国大学生程序设计竞赛 网络选拔赛 I This world need more Zhu
This world need more Zhu Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- OrientDB入门(1)Getting Started
Running OrientDB the First Time First, download and extract OrientDB by selecting the appropriate pa ...
随机推荐
- operator 的两种用法
C++,有时它的确是个耐玩的东东,就比如operator,它有两种用法,一种是operator overloading(操作符重载),一种是operator casting(操作隐式转换).1.操作符 ...
- Asp.net 怎样去除表单多行文本框滚动条
<textarea style="overflow:hidden;border-width:0px;">永远没有滚动条</textarea><text ...
- 去除DEDECMS后台预览文章URL地址多余的数字信息
在使用织梦模板时发现这样一个问题:在后台预览文章的时候,出现的文章网址尽管是静态URL,但是会在网址的尾部出现问号并跟随一个时间戳,在复制URL时就显得很不方便.那么如何解决这一问题呢? 经过查找资料 ...
- 百度地图API示例之添加/删除工具条、比例尺控件
代码 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" cont ...
- A Beginner's Guide To Understanding Convolutional Neural Networks(转)
A Beginner's Guide To Understanding Convolutional Neural Networks Introduction Convolutional neural ...
- C语言的time.h解释python的time
clock_t clock(void),对比python的clock() 返回程序执行的时间,clock_t的实际类型是long #include<Windows.h> Sleep(); ...
- webForm练习1(地区导航)
使用LINQ TO SQL类连接数据库. create database mydb go use mydb go CREATE TABLE [dbo].[ChinaStates] ( ) COLLAT ...
- C#之Winform中treeview控件绑定数据库
private DataSet ds; private SqlDataAdapter sqlDataAdapter1; private int maxnodeid; private void Form ...
- CSS布局--浮动与清除
浮动和清除 浮动和清除是页面布局的重要属性.浮动的意思是指将元素从常规的文档流中取出来. 当你浮动一个元素的时候,浮动的元素会被浏览器尽量的往上放,能放多高就放多高,一直到某个元素的边界为止. 浮动元 ...
- IE内嵌google chrome frame解决浏览器兼容问题
IE内嵌google chrome frame解决浏览器兼容问题 http://www.cnblogs.com/xwdreamer/archive/2013/12/17/3477776.html 参 ...