Atcoder B - Boxes 玄学 + 数学
http://agc010.contest.atcoder.jp/tasks/agc010_b
预处理出每两个相邻的数的差值,那么首先知道是一共取了sum / ((1 + n) * n / 2)次,因为每一次固定要取这么多,所以这个就是操作次数。
然后观察到,每一次操作,都是把dis[]数组的n - 1个减小1,有一个要加上n - 1、最终要变成0
那么问题就是转化成,给定一个数,有两种操作,
第一种是减去1,第二种是加上某一个数,问其在k步后,能否变成0
那么设第一种操作用了x次,第二种操作就是k - x次,那么带入去,能得出一条方程。
dis[i] - x + (k - x) * (n - 1) = 0 (错误了)
不知为何这样错了,很假。
然后题解是设第一种用了k - x次,第二种用了x次。
那么就是dis[i] - (k - x) + x * (n - 1) = 0(能过)
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int maxn = 2e5 + ;
int a[maxn];
vector<int>da;
void work() {
int n;
LL sum = ;
cin >> n;
for (int i = ; i <= n; ++i) {
cin >> a[i];
sum += a[i];
}
LL add = 1LL * n * (n + ) / ;
if (sum % add != ) {
cout << "NO" << endl;
return;
}
for (int i = ; i <= n; ++i) {
da.push_back(a[i] - a[i - ]);
}
da.push_back(a[] - a[n]);
LL k = sum / add;
for (int i = ; i < da.size(); ++i) {
LL t = k - da[i];
// LL t = da[i] + k * (n - 1);
if (t % n != || t < ) {
cout << "NO" << endl;
return;
}
}
cout << "YES" << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}
Atcoder B - Boxes 玄学 + 数学的更多相关文章
- 2018.07.12 atcoder Choosing Points(数学分析好题)
传送门 一句话题意:给出n,d1,d2" role="presentation" style="position: relative;">n,d ...
- CF 990A. Commentary Boxes【数学/模拟】
[链接]:CF [题意]:对于一个数n,每次加一的代价是a,每次减一的代价是b,求被m整除时的最小代价. [分析]:分情况讨论,自己多举几个栗子. [代码]: #include<cstdio&g ...
- HDU 5810 Balls and Boxes ——(数学,概率,方差)
官方题解看不太懂,参考了一些人的博客以后自己证明如下: 其中D(X)和E(X)的公式如下(参考自百度百科): 其中 p = 1 / m .(这是每一个单独事件发生的概率期望,在这里单独事件指的是一个球 ...
- WC2019 自闭记
不咕了 Day 1 2019/1/24 辣么快就到冬令营了,还沉迷于被柿子吊打的状态的菜鸡一时半会还反应不过来.我们学校这次分头去的冬令营,差点上不了车.这次做的动车居然直达广州,强啊. 然鹅还是到太 ...
- Atcoder Grand Contest 010 B - Boxes 差分
B - Boxes 题目连接: http://agc010.contest.atcoder.jp/tasks/agc010_b Description There are N boxes arrang ...
- HDU 5810 Balls and Boxes 数学
Balls and Boxes 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...
- 【HDU 5810多校】Balls and Boxes(打表/数学)
1.打表找规律,下面是打表程序: #include <iostream> #include <cstdio> #define ll long long #define N 10 ...
- UVaLive 7500 Boxes and Balls (数学)
题意:给定 n 个球,每次从每篮子里拿出来一个放在一个新篮子里,并移除相同的,按球的个数进行排序,问你用最多几个球能完成循环. 析:数学问题,很容易发现前n项和就是最多的球数,所以我们只要找最大的n项 ...
- AtCoder Beginner Contest 069【A,水,B,水,C,数学,D,暴力】
A - K-City Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement In K-city, ...
随机推荐
- 万恶之源:C语言中的隐式函数声明
1 什么是C语言的隐式函数声明 在C语言中,函数在调用前不一定非要声明.如果没有声明,那么编译器会自己主动依照一种隐式声明的规则,为调用函数的C代码产生汇编代码.以下是一个样例: int main(i ...
- Part1-Redefining your data-access strategy 重新定义你的数据访问策略
欢迎来到Entity Framework 4 In Action,EF是微软3.5 SP1推出的ORM工具,现在已经更新到4.0版本(...)本书能确保你in a robust and model- ...
- 使用scanf_s报错:0xC0000005: Access violation writing location 0x00000000
在vs2010中写了一行scanf("%s",name); 调式时 提示warning , 提示修改为scanf()使用可能会存在不安全,建议使用scanf_s() 但是我修改成s ...
- 找不到或无法加载主类 ide 正常执行,但是打包jar后报错 maven 引入本地包
错误: 找不到或无法加载主类 com.myali.TTSmy 问题原因: ide中编译能找到相关包,但是,打包成jar时,本地的jar引入失败 maven将系统用到的包从线上maven仓库下载到本地的 ...
- Entity Framework底层操作封装V2版本号(3)
如今是附加的,组合查询须要的扩展类.大家知道lanmda表达式的组合条件比較麻烦,所以就加了一样一个类,方便进行组合查询: using System; using System.Collections ...
- Apache POI组件操作Excel,制作报表(四)
Apache POI组件操作Excel,制作报表(四) 博客分类: 探索实践 ExcelApacheSpringMVCServlet 上一篇我们介绍了如何制作复杂报表的分析和设计,本篇结合S ...
- python库学习笔记——BeautifulSoup处理子标签、后代标签、兄弟标签和父标签
首先,我们来看一个简单的网页https://www.pythonscraping.com/pages/page3.html,打开后: 右键"检查"(谷歌浏览器)查看元素: 用导航树 ...
- 【Codeforces 915E】 Physical Education Lessons
[题目链接] 点击打开链接 [算法] 线段树,注意数据量大,要动态开点 [代码] #include<bits/stdc++.h> using namespace std; ; ,root ...
- python requests 调用restful api
#!/usr/bin/python# -*- coding: utf-8 -*- import jsonimport requestsfrom urlparse import urljoin BASE ...
- gerrit调试