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 ...
随机推荐
- js动态改变时间
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="C ...
- NHibernate系列文章六:NHibernate数据类型映射
摘要 NHibernate支持所有的数据库数据类型. 以SQL Server数据库为例,下表是NHibernate支持的SQL Server数据库最常见的数据类型对照表. 第一列是NHibernate ...
- 关于php Hash算法的一些整理总结
最近在公司内部的分享交流会上,有幸听到了鸟哥的关于php底层的一些算法的分享,虽然当时有些问题没有特别的明白,但是会后,查阅了各种各样的相关资料,对php的一些核心的hash算法有了进一步的理解和认识 ...
- 解决PHP在IE中下载文件,中文文件名乱码问题
if( stripos($_SERVER['HTTP_USER_AGENT'], 'MSIE')!==false ) $filename = urlencode( $filename ); // 输入 ...
- 【转载】OpenGL超级宝典笔记——GLSL语言基础
变量 GLSL的变量命名方式与C语言类似.变量的名称可以使用字母,数字以及下划线,但变量名不能以数字开头,还有变量名不能以gl_作为前缀,这个是GLSL保留的前缀,用于GLSL的内部变量.当然还有一些 ...
- JavaScript(复习总结)
一.三个常用对话框 1.alert(""):警告对话框,作用是弹出一个警告对话框(最常用) 2.confirm(""):确定对话框,弹出一个带确定和取消按钮的对 ...
- Python 集合方法总结
1.添加一个元素: add(...) Addan element to a set. 1 2 3 4 >>> a = {'shaw',11,22} >>>a. ...
- framebuffer应用编程实践
framebuffer的使用主要包括4个部分: (1):首先需要打开设备文件 /dev/fb0. (2):获取设备的信息.包括可变信息和不可变信息,分别使用两个结构体来进行封装,这两个结构体在 < ...
- DropDownList怎样动态绑定数据库中的某一条数据
用Ajax动态绑定数据库的数据:点击后台查看代码,编写代码如下 if (!IsPostBack) { using (SnailTechDataContext con = new SnailTechDa ...
- 搭建本地MAVEN NEXUS 服务
下载 http://120.192.76.70/cache/www.sonatype.org/downloads/nexus-latest-bundle.zip?ich_args=232fba36ed ...