博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 5353 Average
阅读量:6069 次
发布时间:2019-06-20

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

Problem Description
There are 
n soda sitting around a round table. soda are numbered from 
1 to 
n and 
i-th soda is adjacent to 
(i+1)-th soda, 
1-st soda is adjacent to 
n-th soda.
Each soda has some candies in their hand. And they want to make the number of candies the same by doing some taking and giving operations. More specifically, every two adjacent soda 
x and 
y can do one of the following operations only once:
1. 
x-th soda gives 
y-th soda a candy if he has one;
2. 
y-th soda gives 
x-th soda a candy if he has one;
3. they just do nothing.
Now you are to determine whether it is possible and give a sequence of operations.
 

Input
There are multiple test cases. The first line of input contains an integer 
T, indicating the number of test cases. For each test case:
The first contains an integer 
n 
(1n105), the number of soda.
The next line contains 
n integers 
a1,a2,,an 
(0ai109), where 
ai denotes the candy 
i-th soda has.
 

Output
For each test case, output "YES" (without the quotes) if possible, otherwise output "NO" (without the quotes) in the first line. If possible, then the output an integer 
m 
(0mn) in the second line denoting the number of operations needed. Then each of the following 
m lines contain two integers 
x and 
y 
(1x,yn), which means that 
x-th soda gives 
y-th soda a candy.
 

Sample Input
 
3 6 1 0 1 0 0 0 5 1 1 1 1 1 3 1 2 3
 

Sample Output
 
NO YES 0 YES 2 2 1 3 2

这题要注意可能会有从n绕回1的,或者从1绕到n的。感觉情况比較多。

。必须注意2的情况。。

#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;const ll maxn=100005;ll T,n,m,a[maxn],sum,tot;bool flag;int f[maxn][2];int main(){ scanf("%lld",&T); while (T--) { scanf("%lld",&n); sum=0; flag=true; for (int i=0;i
0&&a[k]<=0&&!f[j][1]) { a[k]++; a[j]--; if (!f[k][0]) f[j][1]=1; else f[k][0]=f[j][1]=0; } else if (a[j]<0&&a[k]>=0&&!f[k][0]) { a[k]--; a[j]++; if (!f[j][1]) f[k][0]=1; else f[j][1]=f[k][0]=0; } } for (int i=0;i
n) k=1; if (f[i-1][0]) printf("%d %d\n",i,j); if (f[i-1][1]) printf("%d %d\n",i,k); } } else printf("NO\n"); } return 0;}

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

你可能感兴趣的文章
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderL
查看>>
Bootstrapbutton组
查看>>
为什么多线程、junit 中无法使用spring 依赖注入?
查看>>
CentOS Apache配置详解
查看>>
Spring Mvc Url和参数名称忽略大小写
查看>>
小记5.8面试
查看>>
Linux 文件系统的目录定义
查看>>
【剑指offer】Q17:合并两个排序的链表
查看>>
No.2 PyQt学习
查看>>
阿里安全资深专家杭特辣评中国网络安全人才之“怪现状”
查看>>
MonoDB的数据准备
查看>>
AngularJS------命令行
查看>>
价值1400美元的CEH(道德黑客)认证培训课程长啥样?(3)工具集
查看>>
Docker数据卷
查看>>
vscode常用设置
查看>>
程序员之---C语言细节20(符号和有符号之间转换、两数相加溢出后数值计算)...
查看>>
zookeeper学习
查看>>
【mac】mac上安装软件,报错 鉴定错误,但是安装包都是好的
查看>>
设计模式的6大原则
查看>>
【转】观看视频时启用硬件加速有什么用?如果关闭硬件加速又有什么区别呢?...
查看>>