博客
关于我
Number Game( ZOJ - 3180,思维 + 逆推)
阅读量:251 次
发布时间:2019-03-01

本文共 1628 字,大约阅读时间需要 5 分钟。

一.题目链接:

二.题目大意:

六个数 a,b,c,x,y,z.

每次可进行一次操作,选择一个数,赋值为剩下的两个数相加  - 1.

问是否可以将 x,y,z 转变为 a,b,c. (无序)

三.分析:

正推的话会炸掉.

如果逆推,注意操作的特点.

假设 a,b,c 升序

易得 c == a + b - 1.

则可得上一状态为 a,b, b - a - 1.

网上一些其他的 AC 代码貌似没有考虑全情况,居然过了!woccccc,这么暴力都可以!!!orzzz

比如当 x,y,z 为(1 1 1)或(0 0 0)时会无限循环下去,这里要特判一下.

四.代码实现:

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define eps 1e-6#define PI acos(-1.0)#define ll long long intusing namespace std;int a[3];int b[3];int c[3][3];bool check(){ for(int i = 0; i < 3; ++i) { bool flag = 1; for(int j = 0; j < 3; ++j) { if(a[j] != c[i][j]) { flag = 0; break; } } if(flag) return 1; } return 0;}bool fun(){ bool flag; sort(a, a + 3); sort(b, b + 3); flag = 1; for(int i = 0; i < 3; ++i)///若起初就相等 { if(a[i] != b[i]) flag = 0; } if(flag) return 1; c[0][0] = b[1] + b[2] - 1, c[0][1] = b[1], c[0][2] = b[2];///b的3种下一状态 c[1][0] = b[0] + b[2] - 1, c[1][1] = b[0], c[1][2] = b[2]; c[2][0] = b[1] + b[0] - 1, c[2][1] = b[1], c[2][2] = b[0]; sort(*c, *(c + 1)), sort(*(c + 1), *(c + 2)), sort(*(c + 2), *(c + 3)); flag = 1; for(int i = 0; i < 3; ++i)///操作之后,没有增加的项 { for(int j = 0; j < 3; ++j) { if(c[i][j] > b[j]) flag = 0; } } if(flag) return 0; int cnt = 0; while(1) { cnt++; sort(a, a + 3); if(check()) return 1; else if(a[0] < b[0]) return 0; else a[2] = a[1] - a[0] + 1; }}int main(){ int T; scanf("%d", &T); while(T--) { for(int i = 0; i < 3; ++i) scanf("%d", &a[i]); for(int i = 0; i < 3; ++i) scanf("%d", &b[i]); bool flag = fun(); if(flag) printf("Yes\n"); else printf("No\n"); } return 0;}

 

转载地址:http://vyht.baihongyu.com/

你可能感兴趣的文章
Multimodal Unsupervised Image-to-Image Translation多通道无监督图像翻译
查看>>
MySQL Cluster与MGR集群实战
查看>>
multipart/form-data与application/octet-stream的区别、application/x-www-form-urlencoded
查看>>
mysql cmake 报错,MySQL云服务器应用及cmake报错解决办法
查看>>
Multiple websites on single instance of IIS
查看>>
mysql CONCAT()函数拼接有NULL
查看>>
multiprocessing.Manager 嵌套共享对象不适用于队列
查看>>
multiprocessing.pool.map 和带有两个参数的函数
查看>>
MYSQL CONCAT函数
查看>>
multiprocessing.Pool:map_async 和 imap 有什么区别?
查看>>
MySQL Connector/Net 句柄泄露
查看>>
multiprocessor(中)
查看>>
mysql CPU使用率过高的一次处理经历
查看>>
Multisim中555定时器使用技巧
查看>>
MySQL CRUD 数据表基础操作实战
查看>>
multisim变压器反馈式_穿过隔离栅供电:认识隔离式直流/ 直流偏置电源
查看>>
mysql csv import meets charset
查看>>
multivariate_normal TypeError: ufunc ‘add‘ output (typecode ‘O‘) could not be coerced to provided……
查看>>
MySQL DBA 数据库优化策略
查看>>
multi_index_container
查看>>