POJ 1870 Bee Breeding(找规律)
题意 : 给你一个蜂巢状图形,让你找出两个点之间的距离。
思路 : 在做这个题之前可以看一下2265,因为是一种题来着,规律就是我在2265里写的那样,然后就是求距离了,求距离的时候只需考虑两个点的坐标差值(x,y),把坐标差值分成四个项限,x>0且y>0,或x<0且y<0为abs(x+y),其他情况则是max(abs(x),abs(y))。。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <cstdlib> using namespace std ; void val(int a,int &x,int &y)
{
int n = ;
while( * (n-) * n + < a)
n++;
n--;
if(n == -)
{
x = ;
y = ;
return ;
}
a -= *(n-)*n+;
if(a<=n)
{
x = n-a;
y = a;
}
else if(a>n&&a<=*n)
{
x = n-a;
y = n;
}
else if(a>*n&&a<=*n)
{
x = -n;
y = *n-a;
}
else if(a>*n&&a<=*n)
{
x = a-*n;
y = *n-a;
}
else if(a>*n&&a<=*n)
{
x = a-*n;
y = -n;
}
else
{
x = n;
y = a-*n;
}
}
int main()
{
int a,b ;
while(scanf("%d %d",&a,&b) !=EOF)
{
if(a == && b == ) break ;
int xa,ya,xb,yb ;
val(a,xa,ya) ;
val(b,xb,yb) ;
// printf("%d %d %d %d\n",xa,ya,xb,yb) ;
int ans = ;
if((xa-xb)*(ya-yb) <= )
ans = max(abs(xa-xb),abs(ya-yb)) ;
else ans = abs(xa-xb)+abs(ya-yb) ;
printf("The distance between cells %d and %d is %d.\n",a,b,ans) ;
}
return ;
}
POJ 1870 Bee Breeding(找规律)的更多相关文章
- poj 1870 Bee Breeding
思路:首先要建立坐标,具体作法见:http://www.cnblogs.com/xin-hua/p/3237096.html 然后将得到2坐标之差x,y:如果x,y同号,则相加,否则去最大.(要取绝对 ...
- POJ 2229 Sumsets(找规律,预处理)
题目 参考了别人找的规律再理解 /* 8=1+1+1+1+1+1+1+1+1 1 8=1+1+1+1+1+1+1+2 2 3 8=1+1+1+1+2+2 8=1+1+1+1+4 4 5 8=1+1+2 ...
- POJ 1740 A New Stone Game 又是博弈论配对找规律orz 博弈论 规律
http://poj.org/problem?id=1740 这个博弈一眼看上去很厉害很高大上让人情不自禁觉得自己不会写,结果又是找规律…… 博弈一般后手胜都比较麻烦,但是主要就是找和先手的对应关系, ...
- 【poj 3090】Visible Lattice Points(数论--欧拉函数 找规律求前缀和)
题意:问从(0,0)到(x,y)(0≤x, y≤N)的线段没有与其他整数点相交的点数. 解法:只有 gcd(x,y)=1 时才满足条件,问 N 以前所有的合法点的和,就发现和上一题-- [poj 24 ...
- poj 3372(找规律)
Candy Distribution Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6033 Accepted: 335 ...
- 【poj 2478】Farey Sequence(数论--欧拉函数 找规律求前缀和)
题意:定义 Fn 序列表示一串 <1 的分数,分数为最简分数,且分母 ≤n .问该序列的个数.(2≤N≤10^6) 解法:先暴力找规律(代码见屏蔽处),发现 Fn 序列的个数就是 Φ(1)~Φ( ...
- 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用
转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...
- POJ2992:Divisors(求N!因子的个数,乘性函数,分解n!的质因子(算是找规律))
题目链接:http://poj.org/problem?id=2992 题目要求:Your task in this problem is to determine the number of div ...
- POJ2505 A multiplication game 博弈论 找规律
http://poj.org/problem?id=2505 感觉博弈论只有找规律的印象已经在我心中埋下了种子... 题目大意:两个人轮流玩游戏,Stan先手,数字 p从1开始,Stan乘以一个2-9 ...
随机推荐
- swoole 异步队列
安装步骤如下(推荐把安装文件下载到 /usr/local/src 目录下): step 1: wget --no-check-certificate https://github.com/swoole ...
- android线程间通讯
近来找了一些关于android线程间通信的资料,整理学习了一下,并制作了一个简单的例子. andriod提供了 Handler 和 Looper 来满足线程间的通信.例如一个子线程从网络上下载了一副图 ...
- DrawerLayout带有侧滑功能的布局类(1)
DrawerLayout: DrawerLayout顾名思义就是一个管理布局的.使用方式可以与其它的布局类类似. DrawerLayout带有滑动的功能.只要按照drawerLayout的规定布局方式 ...
- Android--PullToRefreshListView 的简单使用
原文: http://blog.csdn.net/lmj623565791/article/details/38238749; pull-to-refresh对ListView进行了封装,叫做:Pu ...
- hdu 4417 Super Mario/树套树
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 题意很简单,给定一个序列求一个区间 [L, R,]中小于等于H的元素的个数. 好像函数式线段树可 ...
- Erlang generic standard behaviours -- gen
在分析 gen_server (或者是gen_fsm )之前,首先应该弄明白,gen 这个module . -module(gen). -compile({inline,[get_node/1]}). ...
- golang面向对象初识
struct是变量的集合 interface是方法的集合 struct与interface都支持匿名字段, 换言之, 支持组合实现继承. golang的struct与C++的class一样, 只能声明 ...
- Linux下如何使CP命令不提示覆盖
在Linux下使用CP命令,经常会提示是否覆盖,如果是太批量的文件覆盖,老是这么提示,会很烦的.那如何解决这个问题呢? 我们先来看一下原因吧! 一般我们使用的命令是cp -rf sourcefile ...
- java判断某个字符串包含某个字符串的个数
/** * 判断str1中包含str2的个数 * @param str1 * @param str2 * @return counter */ public static int countStr(S ...
- Powershell下设置环境变量
NODE中经常会用到process.env.NODE_ENV来判断当前环境,因为使用的系统是windows,在sublime text下安装terminal插件后,默认启动的时Powershell, ...