先上题目:

D - 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的更多相关文章

  1. Atitit webservice的发现机制 discover机制

    Atitit webservice的发现机制 discover机制 1.1. Ws disconvert 的组播地址和端口就是37021 1.2. Ws disconvert的发现机制建立在udp组播 ...

  2. ACM:SCU 4437 Carries - 水题

    SCU 4437  Carries Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu  Practice  ...

  3. ACM: SCU 4438 Censor - KMP

     SCU 4438 Censor Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu  Practice D ...

  4. ACM: SCU 4440 Rectangle - 暴力

     SCU 4440 Rectangle Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu  Practic ...

  5. SCU 4424(求子集排列数)

    A - A Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice ...

  6. SCU 2941 I NEED A OFFER!(01背包变形)

    I NEED A OFFER!     64bit IO Format: %lld & %llu Submit Status Description Description Speakless ...

  7. SCU 4440 分类: ACM 2015-06-20 23:58 16人阅读 评论(0) 收藏

    SCU - 4440 Rectangle Time Limit: Unknown   Memory Limit: Unknown   64bit IO Format: %lld & %llu ...

  8. scu 4436: Easy Math 水题

    4436: Easy Math Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.scu.edu.cn/soj/problem.actio ...

  9. SCU 4440 Rectangle 2015年四川省赛题

    题目链接:http://acm.scu.edu.cn/soj/problem/4440/ 题目大意:给一个n*m的方格,求周长小于等于k的矩形有多少个. 解题思路:我之前直接暴力,显然超时,所以后来发 ...

随机推荐

  1. bzoj5441: [Ceoi2018]Cloud computing

    跟着大佬做题.. 这题也是有够神仙了.观察一下性质,c很小而f是一个限制条件(然而我并不会心态爆炸) %了一发,就是把电脑和订单一起做背包,订单的c视为负而电脑的v为负,f由大到小排序做背包 #inc ...

  2. canvas制作饼图和环形图,使用Excanvas兼容IE67

    excanvas 地址:http://excanvas.sourceforge.net/ <!DOCTYPE html> <html> <head> <met ...

  3. 【POJ 2676】 Sudoku

    [题目链接] http://poj.org/problem?id=2676 [算法] 深度优先搜索 [代码] #include <algorithm> #include <bitse ...

  4. android 从assets和res中读取文件(转)

    1. 相关文件夹介绍      在Android项目文件夹里面,主要的资源文件是放在res文件夹里面的.assets文件夹是存放不进行编译加工的原生文件,即该文件夹里面的文件不会像xml,java文件 ...

  5. runC爆严重安全漏洞,主机可被攻击!使用容器的快打补丁

    runC 是 Docker,Kubernetes 等依赖容器的应用程序的底层容器运行时.此次爆出的严重安全漏洞可使攻击者以 root 身份在主机上执行任何命令. 容器的安全性一直是容器技术的一个短板. ...

  6. JAVA 中进行网络通信时,通信的程序两端要传输的对象,不仅要序列化,而且这个对象所属的类的名字要完全一样,连包的名字都得一样

    如上图项目目录,这是一个简易的QQ,客户端登录的时候要传输用户信息到服务器验证,所以两端都会用到User类的对象,但一开始我在Server端的包名是com.qq.server.common,两端的报名 ...

  7. POJ 1236 Tarjan算法

    这道题认真想了想.. [ 题目大意:有N个学校,从每个学校都能从一个单向网络到另外一个学校,两个问题 1:初始至少需要向多少个学校发放软件,使得网络内所有的学校最终都能得到软件. 2:至少需要添加几条 ...

  8. Codeforces 609D 被二分教做人

    传送门:http://codeforces.com/problemset/problem/609/D (如需转载,请注明出处,谢谢O(∩_∩)O) 题意: Nura想买k个小玩意,她手上有 s 个bu ...

  9. D - Garden

    Problem description Luba thinks about watering her garden. The garden can be represented as a segmen ...

  10. Hibernate多表映射(三)

    一对多|多对一 一个分类对应多个商品,一个商品只属于一个分类 创建分类表 products用set装,set特点值不能够重复 package com.hibernate.domain; import ...