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的矩形有多少个. 解题思路:我之前直接暴力,显然超时,所以后来发 ...
随机推荐
- Swift版本UIWebView长按保存图片
起因 最近需要做个IOS的壳子,用到长按保存图片的功能,发现百度出来的全是OC语法的例子,很多都不是全面,只能自己写一份Swift版本的,图片下面附上Github地址 效果图 Github地址:htt ...
- SqlServer还原步骤
SqlServer还原步骤 2009-09-05 10:32:12| 分类: 数据库|字号 订阅 1 . 删除原有数据库 新建数据库 hywlxt 2. 在master 中新建存储过程 k ...
- CodeForces - 810C(规律)
C. Do you want a date? time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- hdu 4704(费马小定理+快速幂取模)
Sum Time Limit: 2000/ ...
- UVA 10006(素数打表+快速幂)
当今计算机科学的一个重要的领域就是密码学.有些人甚至认为密码学是计算机科学中唯一重要的领域,没有密码学生命都没有意义. 阿尔瓦罗就是这样的一个人,它正在设计一个为西班牙杂烩菜饭加密的步骤.他在加密算法 ...
- 【BZOJ 1370】 团伙
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1370 [算法] 并查集 + 拆点 [代码] #include<bits/std ...
- java编程基础篇---------> 编写一个程序,从键盘输入三个整数,求三个整数中的最小值。
编写一个程序,从键盘输入三个整数,求三个整数中的最小值. 关键:声明变量temp 与各数值比较. package Exam01; import java.util.Scanner; public ...
- Yearning + Inception SQL审核平台搭建
Yearning 安装: 安装Nginxyum install nginx -y 按照顺序安装MySQLmysql-community-common-5.7.22-1.el6.x86_64.rpmmy ...
- C#判断文件是否存在 //创建txt文件
if(System.IO.File.Exists(@"")) { } if (System.IO.File.Exists(HttpRuntime.AppDomainAppPath ...
- C# 遍历文本框
#region 文本框指定位置加入回车符 private void button1_Click(object sender, EventArgs e) { #region // 查询首字母位置 //s ...