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 ...
随机推荐
- Sql Server 创建表添加说明
http://bbs.csdn.net/topics/340184487 在此感谢 提供参考 CREATE TABLE ToPayFee ( Id INT IDENTITY(1,1) PRIMA ...
- 为什么mongo中不能用int作为key
为什么mongo中不能用int作为key??
- MVC ---- T4模板的小练习
1.先建立两个模板文件 :Manger.ttinclude.DBHelper.ttinclude Manger.ttinclude <#@ assembly name="System. ...
- Ubuntu 14.04 vi 退格键不能删除字符
执行命令 sudo apt-get install vim
- Sublime Text 3.1.1 Build 3176 注册码破解
在hosts(C:\Windows\System32\drivers\etc)加入如下内容: 127.0.0.1 www.sublimetext.com127.0.0.1 li ...
- c assert 用法
#include <stdio.h> /* printf */ #include <assert.h> /* assert */ void print_number(int* ...
- MongoDB(课时17 更新函数)
3.4.3 数据更新操作 MongoDB数据存的是副本数据, 最终的数据还要保存在传统的数据库里,所以如果关系型数据库里数据变了,最好的方法是删除里面的MongoDB数据重新插入. 在MongoDB里 ...
- mysql 超大数据/表管理技巧
如果你对长篇大论没有兴趣,也可以直接看看结果,或许你对结果感兴趣.在实际应用中经过存储.优化可以做到在超过9千万数据中的查询响应速度控制在1到20毫秒.看上去是个不错的成绩,不过优化这条路没有终点,当 ...
- YOLO V3论文理解
YOLO3主要的改进有:调整了网络结构:利用多尺度特征进行对象检测:对象分类用Logistic取代了softmax. 1.Darknet-53 network在论文中虽然有给网络的图,但我还是简单说一 ...
- openstack 问题一览(持续总结中)
★名词 Qemu:它也是一种虚拟化技术,主要提供对IO,网络等外设的虚拟化管理.结合KVM(对CPU和内存管理),提供较为完整的虚拟化管理功能. Libvirt:提供了针对各种虚拟机技术的接口,来管理 ...