B-Boxes
http://agc010.contest.atcoder.jp/tasks/agc010_b
Problem Statement
There are N boxes arranged in a circle. The i-th box contains Ai stones.
Determine whether it is possible to remove all the stones from the boxes by repeatedly performing the following operation:
- Select one box. Let the box be the i-th box. Then, for each j from 1 through N, remove exactly j stones from the (i+j)-th box. Here, the (N+k)-th box is identified with the k-th box.
Note that the operation cannot be performed if there is a box that does not contain enough number of stones to be removed.
Constraints
- 1≦N≦105
- 1≦Ai≦109
Input
The input is given from Standard Input in the following format:
N
A1 A2 … AN
Output
If it is possible to remove all the stones from the boxes, print YES. Otherwise, print NO.
Sample Input 1
5
4 5 1 2 3
Sample Output 1
YES
All the stones can be removed in one operation by selecting the second box.
Sample Input 2
5
6 9 12 10 8
Sample Output 2
YES
Sample Input 3
4
1 2 3 1
Sample Output 3
NO
大致意思是说,假设初始化N个数字为0,选取某一个位置,分别增加1到N(如果到达数组末尾就从头开始)。
比如:
0 0 0(选择第二个位置开始)
3 1 2(选择第三个位置开始)
5 4 3(选择第 X 个位置开始)
.......
给出N个数字,看看是不是由以上操作得到的,是的话输出YES,不是输出NO;
对于数据,记录其和,则K=(n*(n+1))/2为操作次数,另d[i]=a[i]-a[i-1];必定有一个的d[i]=n-1;剩下的为1;
且有d[i]-(k-x)+(n-1)*x=0或k-d[i]=nx(x为相对于的d[i]来说异常操作的数),所以,一定有k-d[i]>=0 && (k-d[i])%n==0,
也可以得到(k-d[i])/n的和为k,由此可解题。
#include<iostream>
using namespace std;
const int mod=1e5+;
long long a[mod],b[mod];
int main()
{
long long n,i,sum=,count=,k;
cin>>n;
for(i=;i<=n;i++)
{
cin>>a[i];
b[i]=a[i]-a[i-];
sum+=a[i];
}
b[]=a[]-a[n];
if(sum%(n*(n+)/))//如果k不为整数,直接输出NO
{
cout<<"NO"<<endl;
return ;
}
k=sum/(n*(n+)/);
for(i=;i<=n;i++)
{
if((k-b[i]<) || (k-b[i])%n)
{
cout<<"NO"<<endl;
return ;
}
else count+=(k-b[i])/n;
}
if(count!=k) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
return ;
}
B-Boxes的更多相关文章
- Fedora 24 Gnome Boxes 无法ping通网络
安装Fedora 24在试用虚拟机时发现无法ping通外网. 我傻傻地以为是软件问题. 问题描述: 尝试ping程序来测试网络连通性: (我之前也是ping百度,后来在为了少打字百度了一些比较短的域名 ...
- Problem B Boxes in a Line
省赛B题....手写链表..其实很简单的.... 比赛时太急了,各种手残....没搞出来....要不然就有金了...注:对相邻的元素需要特判..... Problem B Boxes in a Li ...
- Codeforces Round #229 (Div. 2) C. Inna and Candy Boxes 树状数组s
C. Inna and Candy Boxes Inna loves sweets very much. She has n closed present boxes lines up in a ...
- boxes
boxes [英][bɒksɪz][美][bɑ:ksɪz] n.盒( box的名词复数 ); 一盒; 电视; 小亭; v.把…装入盒[箱,匣]中( box的第三人称单数 ); 拳击; 以上结果来自 ...
- Brute Force - B. Candy Boxes ( Codeforces Round #278 (Div. 2)
B. Candy Boxes Problem's Link: http://codeforces.com/contest/488/problem/B Mean: T题目意思很简单,不解释. ana ...
- UVa 103 - Stacking Boxes(dp求解)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- [CareerCup] 9.10 Stack Boxes 垒箱子问题
9.10 You have a stack of n boxes, with widths w., heights hir and depths drThe boxes cannot be rotat ...
- 北京网络赛G BOXES 状态压缩+有序BFS+高维数组判重
#include <bits/stdc++.h> using namespace std; ]; ][]; ][][]; ][][][]; ][][][][]; ][][][][][]; ...
- 找规律 SGU 126 Boxes
题目地址:http://acm.sgu.ru/problem.php?contest=0&problem=126 /* 找规律,智商不够,看了题解 详细解释:http://blog.csdn. ...
- poj 1475 || zoj 249 Pushing Boxes
http://poj.org/problem?id=1475 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=249 Pushin ...
随机推荐
- javascript系列-class4.函数
欢迎加入前端交流群来py: 转载请标明出处! 在火影的世界中存在忍术,忍术是把强大的能量集中在一起以各种各样不同的形式发射出来.怎样使用各种各样的忍术那?通过结印. ...
- Hibernate框架学习(二)——api详解
一.Configuration对象 功能:配置加载类,用于加载主配置,orm元数据加载. //1.创建,调用空参构造(还没有读配置文件) Configuration conf=new Configur ...
- javaEE的开发模式
1.什么是模式 模式在开发过程中总结出的“套路”,总结出的一套约定俗成的设计模式 2.javaEE经历的模式 model1模式: 技术组成:jsp+javaBean model1的弊端:随着业务复杂性 ...
- STM8S103之ADC
如何快速了解ADC,查看Reference manual中ADC registers章节,初步了解到ADC ADC buffer register和ADC data register Analog W ...
- Java中各种修饰符与访问修饰符
Java中各种修饰符与访问修饰符 类: 访问修饰符 修饰符 class 类名称 extends 父类名称 implement 接口名称 (访问修饰符与修饰符的位置可以互换) 访问修饰符 名称 说明 备 ...
- Spring Framework 开发参考手册中文(在线HTML)
https://blog.csdn.net/zfrong/article/details/3971722
- Manacher笔记
(其实还是回文自动机好用,毛子真是牛逼) Manacher #include<iostream> #include<cstring> #include<cstdio> ...
- JMS消息
1.消息可分为3部分:消息头.属性和有效负载 消息头:用于标识消息.声明消息属性及提供路由信息的特殊字段组成. 消息的属性区包含了和该消息有关的附加元数据,这个元数据由应用程序开发者进行设置,或者由J ...
- python 面向对象 继承
什么是继承 继承表达的是一种”是“的关系,比如人是动物 继承是一种创建新类的方式,在python中,新建的类可以继承一个或多个父类,父类又可称为基类或超类,新建的类称为派生类或子类 继承是基于抽象的结 ...
- 【转】 值得推荐的C/C++框架和库 (真的很强大)
[转] 值得推荐的C/C++框架和库 (真的很强大) 值得学习的C语言开源项目 - 1. Webbench Webbench是一个在linux下使用的非常简单的网站压测工具.它使用fork()模拟多个 ...