ZOJ3180 Number Game

要点:

判断后三个数字能否通过上述的变换过程 推出前三个数字 ,我们可以逆向思维考虑 也就是逆着推回去

如果符合后三个数字 或其变换一次的数字(即符合其中一种组合形式) ,则输出yes

其中重要的点: 要将这些数字从小到大排序,便于比较判断, 前三个数字即使不断减小的但也不能小于或等于0

给出代码如下:(有部分注释)

#include<iostream>
#include<algorithm>
using namespace std;
const int N = ; int main()
{
int a[N], b[N];
int t;
cin >> t;
while(t--)
{
for(int i = ; i < ; i++)
{
cin >> a[i];
}
for(int i = ; i < ; i++)
{
cin >> b[i];
} int dp[N][N]; dp[][] = b[];
dp[][] = b[];
dp[][] = b[]; dp[][] = b[] + b[] - ;
dp[][] = b[];
dp[][] = b[]; dp[][] = b[];
dp[][] = b[] + b[] - ;
dp[][] = b[]; dp[][] = b[];
dp[][] = b[];
dp[][] = b[] + b[] - ; for(int i = ; i < ; i++)
{
sort(dp[i], dp[i] + );//将每种情况按从小到大排序
}
while()//因为不知道要将前三个数字变换多少次才能推回到原来的数字
{
int flag ;
sort(a, a+);//每次都将这三个数按从小到大排序 ,便于比较
for(int i = ; i < ; i++)
{
flag = ;
for(int j = ; j < ; j++)
{
if(dp[i][j] != a[j])
{
flag = ;
}
}
if(flag)
{
break;
}
}
if(flag) // 只有三个数符合dp中任何一种情况时,才能确保输出yes;
{
cout << "Yes" << endl;
break;
} if(a[] - a[] + == a[])// 陷入死循环, 并且这三个数不符合dp的任何一种情况
{
cout << "No" << endl;
break;
}
else
{
a[] = a[] - a[] + ;
flag = ;
for(int i = ; i < ; i++)//逐渐逆推回去的过程中,还没到符合情况就已经有负数出现
{
if(a[i] <= )
{
flag = ;
}
}
if(flag == )
{
cout <<"No" << endl;
break;
}
}
}
}
return ;
}

ZOJ3180 Number Game的更多相关文章

  1. JavaScript Math和Number对象

    目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...

  2. Harmonic Number(调和级数+欧拉常数)

    题意:求f(n)=1/1+1/2+1/3+1/4-1/n   (1 ≤ n ≤ 108).,精确到10-8    (原题在文末) 知识点:      调和级数(即f(n))至今没有一个完全正确的公式, ...

  3. Java 特定规则排序-LeetCode 179 Largest Number

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  4. Eclipse "Unable to install breakpoint due to missing line number attributes..."

    Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...

  5. 移除HTML5 input在type="number"时的上下小箭头

    /*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...

  6. iOS---The maximum number of apps for free development profiles has been reached.

    真机调试免费App ID出现的问题The maximum number of apps for free development profiles has been reached.免费应用程序调试最 ...

  7. 有理数的稠密性(The rational points are dense on the number axis.)

    每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.

  8. [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球

    There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...

  9. [LeetCode] Number of Boomerangs 回旋镖的数量

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

随机推荐

  1. 如何获取xml循环体报文内容

    Xml报文格式如下所示:   <body> <FILENAME></FILENAME> <records>20</records> < ...

  2. HDU 6071 Lazy Running(很牛逼的最短路)

    http://acm.hdu.edu.cn/showproblem.php?pid=6071 题意: 1.2.3.4四个点依次形成一个环,现在有个人从2结点出发,每次可以往它相邻的两个结点跑,求最后回 ...

  3. urljoin

    from urlparse import urljoin urljoin("http://www.asite.com/folder/currentpage.html", " ...

  4. Yandex.Algorithm 2011 Round 2 D. Powerful array 莫队

    题目链接:点击传送 D. Powerful array time limit per test 5 seconds memory limit per test 256 megabytes input ...

  5. linux设置端口转发(一键设置)

    linux设置端口转发 #下载rinetd程序并进入文件夹 wget http://www.boutell.com/rinetd/http/rinetd.tar.gz&&tar -xv ...

  6. [ios]"The identity used to sign the executable is no longer valid"错误解决方法

    重新去开发者网站,申请一遍profiles 参考:http://www.bubuko.com/infodetail-982908.html 我出现这个错误的情况,程序提交app store之后,第二天 ...

  7. js实现滑动拼图验证码

    js实现滑动拼图验证码,我这个样式是仿那些大网站做了, 学习用的,只用到前端. 小的个人网站感觉还可以用,大一点的别人用机器一下就破解了. 下面看图示: 样子大概是这样的. 源码在这 百度网盘:    ...

  8. fragment 小结

    1:注意事项   3.0以前的Android 版本要使用FragmentActivity 来装载Fragment ,使用到support v4包.   3.0以后的版本可以直接在Activity里面添 ...

  9. Observable类API

    包java.util 类 Observable public class Observable extends Object 此类表示模型视图范例中的 observable 对象,或者说“数据”.可将 ...

  10. Codeforces 820B - Mister B and Angle in Polygon

    820B - Mister B and Angle in Polygon 思路: 由于正多边形以某个顶点分成的三角形后以这个点为顶点的角都相等,所以可以确定两个点为相邻点,只要再找一个点就够了. 证明 ...