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. Unity3D学习笔记(二十四):MVC框架

    MVC:全名是Model-View-Controller View(视图层 - 顶层) Controller(控制层 - 中层) Model(数据层 - 底层) View(视图层) 说明:展现给玩家的 ...

  2. Codeforces Round #305 (Div. 2) D. Mike and Feet 单调栈

    D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  3. Js页面自动跳转

    //声明 t = 1 var t = 10; function openwin() { t -= 1; if(t==0){ location.href='index2.html'; } setTime ...

  4. shell printf

    printf 可以格式化字符串,还可以制定字符串的宽度.左右对齐方式等.默认 printf 不会像 echo 自动添加换行符,我们可以手动添加 \n. 例子: $ echo "Hello, ...

  5. c++ 查找容器中不满足条件的元素,返回iterator(find_if_not)

    #include <iostream> // std::cout #include <algorithm> // std::find_if_not #include <a ...

  6. ubuntu 14.04 server 能ping通,但不能ssh

    ssh是一种安全协议,主要用于给远程登录会话数据进行加密,保证数据传输的安全,我们可以很方便的用ssh链接工具连接远程服务器进行相关操作,但是在享受这种方便的同时我们需要进行一些配置. 首先我们需要在 ...

  7. [原][OSG][osgBullet][osgworks][bullet]编译osgBullet尝试物理引擎

    相关网址: 类似文章:http://blog.csdn.net/lh1162810317/article/details/17475297 osgBullet官网:http://osgbullet.v ...

  8. Blue_Flke团队项目设计完善&编码测试

    任务1:文档<软件设计方案说明书>github地址:https://github.com/13993013291/ruanjianguigexuqiu 任务2:项目集成开发环境:eclip ...

  9. js匿名函数和闭包总结

    js匿名函数和闭包总结 一.总结 一句话总结:匿名函数的最主要作用是创建闭包,闭包就是将函数内部和函数外部连接起来的一座桥梁.内层的函数可以使用外层函数的所有变量,即使外层函数已经执行完毕.闭包可以用 ...

  10. [Java学习] java泛型通配符和类型参数的范围

    本节先讲解如何限制类型参数的范围,再讲解通配符(?). 类型参数的范围 在泛型中,如果不对类型参数加以限制,它就可以接受任意的数据类型,只要它是被定义过的.但是,很多时候我们只需要一部分数据类型就够了 ...