ZOJ3180 Number Game
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的更多相关文章
- JavaScript Math和Number对象
目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...
- Harmonic Number(调和级数+欧拉常数)
题意:求f(n)=1/1+1/2+1/3+1/4-1/n (1 ≤ n ≤ 108).,精确到10-8 (原题在文末) 知识点: 调和级数(即f(n))至今没有一个完全正确的公式, ...
- Java 特定规则排序-LeetCode 179 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- Eclipse "Unable to install breakpoint due to missing line number attributes..."
Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...
- 移除HTML5 input在type="number"时的上下小箭头
/*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...
- 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.免费应用程序调试最 ...
- 有理数的稠密性(The rational points are dense on the number axis.)
每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.
- [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...
- [LeetCode] Number of Boomerangs 回旋镖的数量
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...
随机推荐
- Ubuntu 14.04 删除软件附加依赖
参考:FlowVisor的学习笔记 eg.mininet $ sudo apt-get remove mininet $ sudo apt-get remove --auto-remove minin ...
- UVa 11400 照明系统设计
https://vjudge.net/problem/UVA-11400 题意: 有一个照明系统需要用到n种灯,每种灯的电压为V,电源费用K,每个灯泡费用为C,需要该灯的数量为L.注意到,电压相同的灯 ...
- Enumerable扩展方法
主要记录一些平时在工作中用到操作Enumerable的常用方法 /// <summary> /// The i enumerable extension. /// </summary ...
- Java入门:零碎的知识点
实例变量经常被称为属性 成员变量和局部变量:前者在类中定义,后者在类的方法中定义且系统不会自动赋初始值 我们创建一个对象的时候实际上执行的是无参的构造方法 静态变量 static String arr ...
- vmware 安装ubuntu
点击自定义硬件 即将完毕 下面就是安装啦
- C# Random循环生成随机数重复问题解决方案
C# Random循环生成随机数重复问题解决方案1.当我们通过Random生成随机数时,习惯的写法如下: int a=new Random().Next(0,100); 然后生成一个数据数没有任何问题 ...
- C#验证中文
C#验证中文的方式有很多种,下面列举了其中几种可供参考,还有正则表达式的验证这里没有写,后面有机会再补上. 方法一: private bool isChina(string msg) { string ...
- vue.js 混入
混入:mixins 一种分发Vue组件中可反复使用的功能的方法. 混入对象可以:包含任意组件选项. 混入对象的选项将被混入该组件本身的选项. 如果有同名选项,在和组件的数据发生冲突时,组件数据优先.混 ...
- PHP函数总结 (一)
<?php /** * 原理: * 函数不调用不执行,定义函数时,会将 * 函数放到内存中代码段,当调用函数时去内存 * 中函数名称所在位置中执行函数体,执行完后 * 将控制权移交回给调用函数的 ...
- 使用python创建mxnet操作符(网络层)
对cuda了解不多,所以使用python创建新的操作层是个不错的选择,当然这个性能不如cuda编写的代码. 在MXNET源码的example/numpy-ops/下有官方提供的使用python编写新操 ...