【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;
}
posted @ 2019-05-13 17:45  sigongzi  阅读(237)  评论(0编辑  收藏  举报