【AtCoder】ARC064
ARC064
C - Boxes and Candies
先把每个盒子都消到x
然后从前往后推,要求第二个的上界是x-前一个
因为我们要求靠后的那个尽量小,会对后面的修改影响尽量小
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N;
int64 a[MAXN],x,ans;
void Solve() {
read(N);read(x);
for(int i = 1 ; i <= N ; ++i) {
read(a[i]);
if(a[i] > x) {
ans += a[i] - x;
a[i] = x;
}
}
int64 t = 0;
for(int i = 2 ; i <= N ; ++i) {
int64 m = x - a[i - 1];
if(a[i] > m) {t += a[i] - m;a[i] = m;}
}
out(ans + t);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
D - An Ordinary Game
最后的串长度的奇偶性是一定的
例如两端是a和c,最后的串一定是acac,或者acacacac
两端是a的话最后的一定是aba,或者ababa,b可以换成任意字母
我们看看两个串的长度的差值是奇数还是偶数
然后根据奇偶性判断胜负即可
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
char s[MAXN];
int L;
void Solve() {
scanf("%s",s + 1);
L = strlen(s + 1);
if(s[1] == s[L]) {
--L;
if(L & 1) puts("First");
else puts("Second");
}
else {
if(L & 1) puts("First");
else puts("Second");
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
E - Cosmic Rays
就是跑一遍dij就行,两个圆之间的距离要么是0要么是圆心距减两个半径
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 1005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
struct Point {
db x,y;
Point(db _x = 0.0,db _y = 0.0) {x = _x;y = _y;}
friend Point operator + (const Point &a,const Point &b) {
return Point(a.x + b.x,a.y + b.y);
}
friend Point operator - (const Point &a,const Point &b) {
return Point(a.x - b.x,a.y - b.y);
}
db norm() {
return sqrt(x * x + y * y);
}
}P[MAXN],S,T;
db R[MAXN],dis[MAXN];
int N;
bool vis[MAXN];
void Solve() {
scanf("%lf%lf%lf%lf",&S.x,&S.y,&T.x,&T.y);
read(N);
for(int i = 1 ; i <= N ; ++i) {
scanf("%lf%lf%lf",&P[i].x,&P[i].y,&R[i]);
dis[i] = max(0.0,(S - P[i]).norm() - R[i]);
}
for(int i = 1 ; i <= N ; ++i) {
int u = -1;
for(int j = 1 ; j <= N ; ++j) {
if(!vis[j]) {
if(u == -1) u = j;
else if(dis[j] < dis[u]) u = j;
}
}
vis[u] = 1;
for(int j = 1 ; j <= N ; ++j) {
if(!vis[j]) {
dis[j] = min(dis[j],dis[u] + max(0.0,(P[u] - P[j]).norm() - R[u] - R[j]));
}
}
}
db ans = (S - T).norm();
for(int i = 1 ; i <= N ; ++i) {
ans = min(ans,dis[i] + max(0.0,(P[i] - T).norm() - R[i]));
}
printf("%.10lf\n",ans);
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
F - Rotated Palindromes
记\(f(i)\)为长度为i个回文串个数,不含循环节
\(f(i) = K^{\lceil \frac{i}{2} \rceil} - \sum_{d|i}f(d)\)
由于i只有\(O(\sqrt{N})\)个且转移关系并不多,所以\(f(i)\)都可以很快求出来
然后我们答案就是
\(\sum_{d|N}d\cdot f(d)[d \%2 == 1] + \sum_{d|N}\frac{d}{2} \cdot f(d)[d \% 2 == 0]\)
因为d如果是2的倍数,转一半的时候会构成一个新的d长度回文串,重复统计了
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 1005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N,K;
map<int,int> zz;
int inc(int a,int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
return 1LL * a * b % MOD;
}
void update(int &x,int y) {
x = inc(x,y);
}
int fpow(int x,int c) {
int res = 1,t = x;
while(c) {
if(c & 1) res = mul(res,t);
t = mul(t,t);
c >>= 1;
}
return res;
}
int f(int x) {
if(x == 1) return K;
if(zz.count(x)) return zz[x];
int res = fpow(K,x / 2);
if(x & 1) res = mul(res,K);
for(int i = 1 ; i <= x / i ; ++i) {
if(x % i == 0) {
update(res,MOD - f(i));
int j = x / i;
if(j != i && j != x) update(res,MOD - f(j));
}
}
zz[x] = res;
return res;
}
void Solve() {
read(N);read(K);
int ans = 0;
for(int i = 1 ; i <= N / i; ++i) {
if(N % i == 0) {
int t = mul(f(i),i);
if(i % 2 == 0) t = mul(t,(MOD + 1) / 2);
update(ans,t);
int j = N / i;
t = mul(f(j),j);
if(j % 2 == 0) t = mul(t,(MOD + 1) / 2);
if(j != i) update(ans,t);
}
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
【AtCoder】ARC064的更多相关文章
- 【AtCoder】ARC092 D - Two Sequences
[题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...
- 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring
[题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...
- 【AtCoder】ARC 081 E - Don't Be a Subsequence
[题意]给定长度为n(<=2*10^5)的字符串,求最短的字典序最小的非子序列字符串. http://arc081.contest.atcoder.jp/tasks/arc081_c [算法]字 ...
- 【AtCoder】AGC022 F - Leftmost Ball 计数DP
[题目]F - Leftmost Ball [题意]给定n种颜色的球各k个,每次以任意顺序排列所有球并将每种颜色最左端的球染成颜色0,求有多少种不同的颜色排列.n,k<=2000. [算法]计数 ...
- 【AtCoder】AGC005 F - Many Easy Problems 排列组合+NTT
[题目]F - Many Easy Problems [题意]给定n个点的树,定义S为大小为k的点集,则f(S)为最小的包含点集S的连通块大小,求k=1~n时的所有点集f(S)的和取模92484403 ...
- 【AtCoder】ARC067 F - Yakiniku Restaurants 单调栈+矩阵差分
[题目]F - Yakiniku Restaurants [题意]给定n和m,有n个饭店和m张票,给出Ai表示从饭店i到i+1的距离,给出矩阵B(i,j)表示在第i家饭店使用票j的收益,求任选起点和终 ...
- 【AtCoder】ARC095 E - Symmetric Grid 模拟
[题目]E - Symmetric Grid [题意]给定n*m的小写字母矩阵,求是否能通过若干行互换和列互换使得矩阵中心对称.n,m<=12. [算法]模拟 [题解]首先行列操作独立,如果已确 ...
- 【Atcoder】AGC022 C - Remainder Game 搜索
[题目]C - Remainder Game [题意]给定n个数字的序列A,每次可以选择一个数字k并选择一些数字对k取模,花费2^k的代价.要求最终变成序列B,求最小代价或无解.n<=50,0& ...
- 【Atcoder】AGC 020 B - Ice Rink Game 递推
[题意]n个人进行游戏,每轮只保留最大的a[i]倍数的人,最后一轮过后剩余2人,求最小和最大的n,或-1.n<=10^5. [算法]递推||二分 [题解]令L(i),R(i)表示第i轮过后的最小 ...
随机推荐
- Python3使用openpyxl读写Excel文件
Python中常用的操作Excel的三方包有xlrd,xlwt和openpyxl等,xlrd支持读取.xls和.xlsx格式的Excel文件,只支持读取,不支持写入.xlwt只支持写入.xls格式的文 ...
- Robot Framework(十六) 扩展RobotFramework框架——使用监听器接口
4.3使用监听器接口 Robot Framework有一个侦听器接口,可用于接收有关测试执行的通知.监听器是具有某些特殊方法的类或模块,它们可以用Python和Java实现.监听器接口的示例用法包括外 ...
- jenkins权限问题
今天用jenkins的时候,构建失败,看了下控制台输出,提示是缺少权限,以前也遇到过这个问题,当时是通过把相关文件夹权限设置为777解决的,这种办法有两个不好的地方,一是这样一来任何用户都能操作这个文 ...
- docker 部署 .net core
1.centos安装好sdk2.1,安装好docker,这些基本的操作就不赘述. 2.准备好core项目,版本2.1 3.新建dockerfile文件放到项目发布文件夹里,里面内容如下: FROM m ...
- 5G 与 MEC 边缘计算
目录 文章目录 目录 前言 参考文献 通信网络 核心网演进之路 早古时期 2G 网络架构 3G 网络架构 4G 网络架构 5G 5G 网络的需求 5G 网络架构的设计原则 5G 网络的逻辑架构 5G ...
- 《图解 HTTP》读书笔记
<图解 HTTP>一书是日本学者上野宣所著,2014 年由于均良先生翻译并在国内出版.因为作者使用十分生动的语言和浅显易懂的案例将 HTTP 协议讲解得深入浅出,所以深受开发者喜爱.现在在 ...
- tomcat 8.xxx ssl使用websocket Failed to close the ServletOutputStream connection cleanly
报错: 2019-09-17 10:30:17.277 default [https-jsse-nio-8110-exec-20] INFO o.a.t.w.s.WsRemoteEndpointImp ...
- 给数据库授权,否则程序、navicat无法连接数据库的,每创建一个数据库都要给数据库授权
给数据库授权,否则程序.navicat无法连接test1数据库的 mysql> grant all privileges on test1.* TO 'root'@'%' identified ...
- C-Lodop提示Access violation at address ...in module 'CLodopPrint32.exe' write of address
C-Lodop提示 Access violation at address ……in module 'CLodopPrint32.exe' write of address ……最近遇到了个问题,上午 ...
- 人人都可以写的可视化Python小程序第二篇:旋转的烟花
兴趣是最好的老师 枯燥的编程容易让人放弃,兴趣才是最好的老师.无论孩子还是大人,只有发现这件事情真的有趣,我们才会非常执着的去做这件事,比如打游戏.如果编程能像玩游戏一样变得有趣,我相信很多人就特别愿 ...