LonLife 1071 - Boring Game
来源:互联网 发布:狙击电话亭解析 知乎 编辑:程序博客网 时间:2024/05/17 03:00
Time Limit:1s Memory Limit:1024MByte
Submissions:595Solved:189
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 the ith 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<string.h>#include<algorithm>using namespace std;int sum1[110000],sum2[110000];int main(){int t,n,m,i,j,k,a,b;scanf("%d",&t);while(t--){scanf("%d",&n);sum1[0]=0;sum2[0]=0;for(i=1;i<=n;i++){scanf("%d",&a);sum1[i]=sum1[i-1]+a;}sort(sum1+1,sum1+n+1);for(i=1;i<=n;i++){scanf("%d",&b);sum2[i]=sum2[i-1]+b;}sort(sum2+1,sum2+n+1);int flag=0;for(i=1;i<n;i++){if(sum1[i]!=sum2[i]){flag=1;break;}}if(flag){printf("No\n");}else{printf("Yes\n");}}return 0;}
- LonLife 1071 - Boring Game
- 玲珑oj 1071 - Boring Game
- Boring Game
- 玲珑Round #7-1071 - Boring Game
- 玲珑学院OJ 1071 Boring Game【思维】
- HDU 2419 Boring Game
- hdu 4592 Boring Game
- hdu 2419 Boring Game
- 玲珑杯-Boring Game
- A Boring Game
- zoj 3352 Boring Board Game
- HDU 4592 Boring Game(高斯消元好题)
- 南开 2216: Boring Game (排序)
- [ZOJ 3352] Boring Board Game [动态规划]
- 【玲珑杯R7 A】Boring Game
- Boring
- Boring
- boring
- sqoop导入mysql数据到hbase
- 自定义控件
- git操作
- opencv学习(十八)之图像方框滤波BoxBlur
- 复杂的ListView,多条目加载
- LonLife 1071 - Boring Game
- NVCC 分歩 编译 CUDA 程序
- Linq查询
- Mac 查看localhost 对应的ip
- 1. Redis 安装与运行
- 在线 PHP运行工具、数据库可控
- 2016年圣诞节巨献:C#汉诺塔河内塔游戏(动画、圣诞节音效)源码及安装包
- # (vish-4014) No objects found matching '/test/*'解决方法。
- 遗传算法与直接搜索工具箱学习笔记(补充)三维立体绘图方法