Boring Game
来源:互联网 发布:java运行jar包中的类 编辑:程序博客网 时间:2024/05/22 06:23
Time Limit:1s Memory Limit:1024MByte
Submissions:541Solved:155
In a mysterious cave, PigVan ( Mr.Van's pet ) has lived for thousands years. PigVan absorbed the power of nature, and it may pretend a human in speaking, walking and so on.
One day, he bought some valuable stone, and divided them into n piles of stone where theith pile (1≤i≤n) contains valuesai .
After PigVan put them in a line, he wants to play a game.
In the boring game, he can do this operation:
Choose a stone pile ai (i>1)and its two adjacent piles ai-1, ai+1, turn(ai-1, ai, ai+1) to(ai-1 + ai, -ai, ai + ai+1).
PigVan wonders whether he can get (b1, b2, b3, …, bn) after several operations.
Note:
If you choose the last pile an, the operation will be( an-1 + an, -an ) .
For each test case:
In the first line, there are only one integer nn(n≤105), indicating the number of food piles.
The second line is nn integers indicate sequence aa ( | ai | ≤ 106).
The third line is nn integers indicate sequence bb ( | bi | ≤ 106).
(ai-1, ai, ai+1)->(ai-1 + ai, -ai, ai+1 + ai)
如果考虑前缀和,那么一次操作等效为
(si-1, si, si+1)->(si, si-1, si+1)
即对于前缀和而言,他只是交换了位置。
因此,我们只需求出前缀和,然后看元素是否对等就行了。
#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>using namespace std;int a[1000000],b[1000000];int c[1000000],d[1000000];int main(){ int t; scanf("%d",&t); while(t--) { int n; memset(c,0,sizeof(c)); memset(d,0,sizeof(d)); scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); c[i]=c[i-1]+a[i]; } for(int i=1;i<=n;i++) { scanf("%d",&b[i]); d[i]=d[i-1]+b[i]; } sort(c+1,c+n+1); sort(d+1,d+n+1); int sum=0; for(int i=1;i<=n;i++) { if(c[i]==d[i]) { sum++; } } if(sum==n) { printf("Yes\n"); } else printf("No\n"); }}
- Boring Game
- HDU 2419 Boring Game
- hdu 4592 Boring Game
- hdu 2419 Boring Game
- LonLife 1071 - Boring Game
- 玲珑杯-Boring Game
- A Boring Game
- zoj 3352 Boring Board Game
- HDU 4592 Boring Game(高斯消元好题)
- 玲珑oj 1071 - Boring Game
- 南开 2216: Boring Game (排序)
- [ZOJ 3352] Boring Board Game [动态规划]
- 【玲珑杯R7 A】Boring Game
- 玲珑Round #7-1071 - Boring Game
- 玲珑学院OJ 1071 Boring Game【思维】
- Boring
- Boring
- boring
- 性能测试TPS目标值确定-二八原则
- thinkphp3.2链接数据库报No such file or directory错误解决方案
- 封装一个自己的mvc框架
- java面试题(五)
- JAVA 黑白棋
- Boring Game
- 数据流中的中位数
- py-faster-rcnn + ZF 实现自己的数据训练与检测(二)
- PostgreSQL学习篇9.14 XML类型
- nil / Nil / NULL / NSNull
- BZOJ 1711 Dining 吃饭 网络流
- 浅谈二分查找法
- test_one
- C++编译过程常出现的错误