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. 读jQuery源码有感2

    那么就来读读jQuery源码的Callbacks部分. 一上来看原版源码 jQuery.Callbacks = function( options ) { // Convert options fro ...

  2. python 连加

    sum= number=int(input('请输入整数: ')) #递增for循环,从小到大打印出数字 print('从小到大排列输出数字:') ,number+): sum+=i #设置sum为i ...

  3. MongoDB(课时10 数组)

    3.4.2.5 数组查询 MongoDB里面支持数组保存,一旦支持数组保存,就需要对于数组的数据进行匹配. 范例:插入一部分数组内容 课程是数组的形式(截图时少截一条信息) 此时数据包含数组内容,而后 ...

  4. Cocoapods 报警告Automatically assigning platform ios with version 9.0 on target....

    Automatically assigning platform iOS with version 9.0 on target 你的工程名称 because no platform was speci ...

  5. RabbitMQ入门_06_深入了解ack

    A. Delivery Tag 参考资料:https://www.rabbitmq.com/confirms.html 仔细查看一下 Consumer 的回调方法: public void handl ...

  6. spring boot: GlobalDefaultExceptionHandler方法内的友好错误提示,全局异常捕获

    spring boot: GlobalDefaultExceptionHandler方法内的友好错误提示,全局异常捕获 当你的某个控制器内的某个方法报错,基本上回显示出java错误代码,非常不友好,这 ...

  7. How to implement connection pool in spark streaming

    在spark streaming的文档里,有这么一段: def sendPartition(iter): # ConnectionPool is a static, lazily initialize ...

  8. 第五章 [BX]和loop指令

    5.1 [bx] [bx]是什么 和 [0] 有些类似,[0] 表示内存单元,它的偏移地址是 0. 例如: mov ax, [0] 内存以字节为单位:ax以字(16bit = 2Byte)为单位:al ...

  9. 12月13日 什么是help_method,session的简单理解, find_by等finder method

    helper_method Declare a controller method as a helper. For example, helper_method :link_to def link_ ...

  10. array_unshift

    <!DOCTYPE html> <html> <body> <?php $a=array(0=>"red",1=>" ...