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的更多相关文章

  1. 【AtCoder】ARC092 D - Two Sequences

    [题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...

  2. 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring

    [题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...

  3. 【AtCoder】ARC 081 E - Don't Be a Subsequence

    [题意]给定长度为n(<=2*10^5)的字符串,求最短的字典序最小的非子序列字符串. http://arc081.contest.atcoder.jp/tasks/arc081_c [算法]字 ...

  4. 【AtCoder】AGC022 F - Leftmost Ball 计数DP

    [题目]F - Leftmost Ball [题意]给定n种颜色的球各k个,每次以任意顺序排列所有球并将每种颜色最左端的球染成颜色0,求有多少种不同的颜色排列.n,k<=2000. [算法]计数 ...

  5. 【AtCoder】AGC005 F - Many Easy Problems 排列组合+NTT

    [题目]F - Many Easy Problems [题意]给定n个点的树,定义S为大小为k的点集,则f(S)为最小的包含点集S的连通块大小,求k=1~n时的所有点集f(S)的和取模92484403 ...

  6. 【AtCoder】ARC067 F - Yakiniku Restaurants 单调栈+矩阵差分

    [题目]F - Yakiniku Restaurants [题意]给定n和m,有n个饭店和m张票,给出Ai表示从饭店i到i+1的距离,给出矩阵B(i,j)表示在第i家饭店使用票j的收益,求任选起点和终 ...

  7. 【AtCoder】ARC095 E - Symmetric Grid 模拟

    [题目]E - Symmetric Grid [题意]给定n*m的小写字母矩阵,求是否能通过若干行互换和列互换使得矩阵中心对称.n,m<=12. [算法]模拟 [题解]首先行列操作独立,如果已确 ...

  8. 【Atcoder】AGC022 C - Remainder Game 搜索

    [题目]C - Remainder Game [题意]给定n个数字的序列A,每次可以选择一个数字k并选择一些数字对k取模,花费2^k的代价.要求最终变成序列B,求最小代价或无解.n<=50,0& ...

  9. 【Atcoder】AGC 020 B - Ice Rink Game 递推

    [题意]n个人进行游戏,每轮只保留最大的a[i]倍数的人,最后一轮过后剩余2人,求最小和最大的n,或-1.n<=10^5. [算法]递推||二分 [题解]令L(i),R(i)表示第i轮过后的最小 ...

随机推荐

  1. DEVICE_ATTR设置设备属性

    DEVICE_ATTR设置设备属性 为了在sysfs下生成可控节点,方便上层调用. sysfs是一个基于RAM的文件系统,它和Kobject一起,可以将Kernel的数据结构导出到用户空间,以文件目录 ...

  2. Luogu5339 [TJOI2019]唱、跳、rap和篮球 【生成函数,NTT】

    当时看到这道题的时候我的脑子可能是这样的: My left brain has nothing right, and my right brain has nothing left. 总之,看到&qu ...

  3. centos7初始化脚本(转)

    #!/bin/bash # 描述: CentOS 初始化脚本 # 加载配置文件 if [ -n "${1}" ];then /bin/} fi # 可接受配置(shell 变量格式 ...

  4. 二十五、grub (Boot Loader) 以及修复grub

    双系统安装(先Windows后Linux,以免windows NTloader会覆盖Linux loader) GRUB Grand Uniform Bootloader CentOS5,6 grub ...

  5. redis详解之cluster模式部署

    一.环境说明 1.Operation OS:CentOS7.22.ruby version >= 2.2.23.openssl zlib gcc>=4.8.5 二.开始部署 1.安装rub ...

  6. Java连接Memcached进行CRUD

    参考这篇博文在本机安装了Memcached 在 Java 中常用的memcached有三个: Memcached Client for Java SpyMemcached XMemcached 这里使 ...

  7. 一步一步学习FastJson1.2.47远程命令执行漏洞

    本文首发于先知:https://xz.aliyun.com/t/6914 漏洞分析 FastJson1.2.24 RCE 在分析1.2.47的RCE之前先对FastJson1.2.24版本中的RCE进 ...

  8. RabbitMQ JAVA客户端调用例子

    1.安装erlang 下载地址:http://www.erlang.org/downloads 设置ERLANG环境变量 2.安装RabbitMQ 下载地址: http://www.rabbitmq. ...

  9. APP_DEBUG改成false上线之后发现:“页面错误!请稍后再试~

      TP框架 页面错误!请稍后再试 把APP_DEBUG改成false上线之后发现:"页面错误!请稍后再试-". 问题一般是出在,display() 指定某个具体的模板文件后win ...

  10. ThinkPHP使用smarty模板引擎的方法

    ThinkPHP支持多种php模板引擎,可以根据个人需要加以配置.下面我们以Smarty模板引擎为例,给大家说说具体的操作流程! 首先去Smarty官网上下载一个Smarty.本站下载地址:http: ...