SCU - 4117 - Discover
先上题目:
Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Description
Time Limit: 3000 MS Memory Limit: 65536 K
Description
GLC has developed an algorithm to map each lattice point in the 2-d catesian coordinates to a nature number. For example:
(0, 0) -> 0
(1, 0) -> 1
(1, 1) -> 2
(0, 1) -> 3
(-1, 1)-> 4
...
and so on. If we connect every two adjacent points by a segment, we get a spiral line which starts at (0, 0).
Now, given a point on the plane, you are to find the nature number it mapped to.

Input
The first line of input is the number of test case.
For each test case, thers is only one line contains two number x , y ( |x|, |y| <= 10,000 ).
Output
for each test case, output the answer in one line.
Sample Input
2
2 3
3 4
Sample Output
31
57 题意:以(0,0)点为起点(零号点),作逆时针回旋矩阵,给出坐标,求出是第几个数。
直接模拟。根据分析,可以发现想一个方向前进的长度变化是每转两次方向加一。对于要判断目标点是不是在某一段上,我们需要判断这某一段的端点是不是都相等而且等于目标点的其中一个坐标,然后另一个坐标在端点对应坐标之间。不过注意端点的坐标大小不一定是从小到大排的,所以需要分情况讨论。然后统计一下中间的移动步数就可以了。 上代码:
#include <cstdio>
#include <cstring>
using namespace std; int cy[]={,,,-};
int cx[]={,,-,};
int a,b;
int u;
inline bool check(int l,int m,int r){
if(l<=m && m<=r){
u=m-l;
return ;
}
if(r<=m && m<=l){
u=l-m;
return ;
}
return ;
} int deal(){
int c,i,x,y,x0,y0,ans;
c=,i=;
x=y=;
ans=;
while(){
i++;
for(int j=;j<;j++){
y0=y+cy[c]*i;
x0=x+cx[c]*i;
c=(c+)%;
//printf("%d %d\n",x0,y0);
if(x==x0 && a==x && check(y,b,y0)){
ans+=u;
return ans;
}else if(y==y0 && y0==b && check(x,a,x0)){
ans+=u;
return ans;
}
ans+=i;
y=y0;
x=x0;
}
}
return -;
} int main()
{
int t;
//freopen("data.txt","r",stdin);
scanf("%d",&t);
while(t--){
scanf("%d %d",&a,&b);
printf("%d\n",deal());
}
return ;
}
4117
SCU - 4117 - Discover的更多相关文章
- Atitit webservice的发现机制 discover机制
Atitit webservice的发现机制 discover机制 1.1. Ws disconvert 的组播地址和端口就是37021 1.2. Ws disconvert的发现机制建立在udp组播 ...
- ACM:SCU 4437 Carries - 水题
SCU 4437 Carries Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu Practice ...
- ACM: SCU 4438 Censor - KMP
SCU 4438 Censor Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu Practice D ...
- ACM: SCU 4440 Rectangle - 暴力
SCU 4440 Rectangle Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu Practic ...
- SCU 4424(求子集排列数)
A - A Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Practice ...
- SCU 2941 I NEED A OFFER!(01背包变形)
I NEED A OFFER! 64bit IO Format: %lld & %llu Submit Status Description Description Speakless ...
- SCU 4440 分类: ACM 2015-06-20 23:58 16人阅读 评论(0) 收藏
SCU - 4440 Rectangle Time Limit: Unknown Memory Limit: Unknown 64bit IO Format: %lld & %llu ...
- scu 4436: Easy Math 水题
4436: Easy Math Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.scu.edu.cn/soj/problem.actio ...
- SCU 4440 Rectangle 2015年四川省赛题
题目链接:http://acm.scu.edu.cn/soj/problem/4440/ 题目大意:给一个n*m的方格,求周长小于等于k的矩形有多少个. 解题思路:我之前直接暴力,显然超时,所以后来发 ...
随机推荐
- Qt为啥从4.8直接就跳到5.3了呢?这不科学吧
http://qt-project.org/downloads Qt 5.3 Select the file according to your operating system from the l ...
- oc63--协议@protocol1
// // SportProtocol.h // day17 #import <Foundation/Foundation.h> @protocol SportProtocol <N ...
- How to use shared model by git in sql source control of red gate
1.clone the git repository for datbase 2.open sql source control window and select the target databa ...
- 感知器算法 C++
We can estimate the weight values for our training data using stochastic gradient descent. Stochasti ...
- Java压缩技术(三) ZIP解压缩——Java原生实现
原文:http://snowolf.iteye.com/blog/642492 JavaEye的朋友跟我说:“你一口气把ZIP压缩和解压缩都写到一个帖子里,我看起来很累,不如分开好阅读”.ok,面向读 ...
- sentcms,thinkphp网站管理系统
SentCMS网站管理系统是南昌腾速科技有限公司倾力打造的一款简单易用的网站管理系统,SentCMS网站管理系统(下文简称SentCMS)继承了thinkphp5.0的优秀品质,秉承“大道至简”的设计 ...
- 消除svn选定(checkout)桌面上文件显示一大堆问号。
图片: 解决方法一: 桌面右键选择TortoiseSVN——>点击Settings,如下图,选中Icon Overlays(图标覆盖),去勾选Fixed drives(本地磁盘),点击确定,按F ...
- elasticsearch性能调优
转载 http://www.cnblogs.com/hseagle/p/6015245.html 该es调优版本可能有低,但是思想主体不变,不合适的参数可以自己找最新的版本相应的替代,或者增删 ela ...
- 【C++】cin、cout的效率比scanf和printf低的解决方法
玩竞赛的同学应该发现了C++中直接调用cout.cin的效率要比printf和scanf的效率要低. 要解决这个问题,只需要在前面加上一句 std::ios::sync_with_stdio(fals ...
- 编码的来历和使用 utf-8 和GB2312比较
经常我们打开外国网站的时候出现乱码,又或者打开很多非英语的外国网站的时候,显示的都是口口口口口的字符, wordpress程序是用的UTF-8,很多cms用的是GB2312. ● 为什么有这么多编码? ...