为啥这场ARC那么水……一个点就切完了

ARC059

C - いっしょ / Be Together

枚举就行

#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[105]; void Solve() {
read(N);
for(int i = 1 ; i <= N ; ++i) read(a[i]);
int64 ans = 1e18;
for(int64 i = -100 ; i <= 100 ; ++i) {
int64 tmp = 0;
for(int j = 1 ; j <= N ; ++j) {
tmp += (a[j] - i) * (a[j] - i);
}
ans = min(ans,tmp);
}
out(ans);enter;
} int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

D - アンバランス / Unbalanced

要么是两个相邻的字母相同,要么是两个相同的字母中间隔了一个

其余的情况都会至少包含这两种情况之一

所以只要判这两种就好了

#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 N;
void Solve() {
scanf("%s",s + 1);
N = strlen(s + 1);
for(int i = 1 ; i < N ; ++i) {
if(s[i] == s[i + 1]) {out(i);space;out(i + 1);enter;return;}
if(i != N - 1) {
if(s[i] == s[i + 2]) {out(i);space;out(i + 2);enter;return;}
}
}
out(-1);space;out(-1);enter;
} int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

E - キャンディーとN人の子供 / Children and Candies

每个值其实可以分开考虑

设\(dp[i][j]\)为前i个数指数的总和为j的和,枚举下一个数的指数,计算从\([A_{i + 1},B_{i + 1}]\)的所有情况,更新即可

#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 405
//#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;
int C,A[MAXN],B[MAXN];
int num[MAXN][MAXN],sum[MAXN][MAXN];
int dp[2][MAXN];
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);
}
void Solve() {
read(N);read(C);
for(int i = 1 ; i <= N ; ++i) read(A[i]);
for(int i = 1 ; i <= N ; ++i) read(B[i]);
for(int i = 1 ; i <= 400 ; ++i) {
num[i][0] = 1;
for(int j = 1 ; j <= 400 ; ++j) {
num[i][j] = mul(num[i][j - 1],i);
}
}
for(int j = 0 ; j <= 400 ; ++j) {
for(int i = 1 ; i <= 400 ; ++i) {
sum[i][j] = inc(sum[i - 1][j],num[i][j]);
}
}
int cur = 0;dp[cur][0] = 1;
for(int i = 1 ; i <= N ; ++i) {
memset(dp[cur ^ 1],0,sizeof(dp[cur ^ 1]));
for(int j = 0 ; j <= C ; ++j) {
for(int h = 0 ; h <= C - j ; ++h) {
update(dp[cur ^ 1][j + h],mul(dp[cur][j],inc(sum[B[i]][h],MOD - sum[A[i] - 1][h])));
}
}
cur ^= 1;
}
out(dp[cur][C]);enter;
} int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

F - バイナリハック / Unhappy Hacking

这个题就是,我如果新加一个值,默认和我需要的下一位相同,而我摁下一个B后,当前最后一位的值就不必要是和s中对应位置相同了,于是方案数乘2

设\(dp[i][j]\)为第i次操作,字符串长度为j,这样dp即可

#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 5005
//#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 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);
}
char s[5005];
int dp[5005][5005],N,L; void Solve() {
read(N);
scanf("%s",s + 1);
L = strlen(s + 1);
dp[0][0] = 1;
for(int i = 0 ; i < N ; ++i) {
for(int j = 0 ; j <= N ; ++j) {
if(j == 0) update(dp[i + 1][j],dp[i][j]);
else update(dp[i + 1][j - 1],mul(dp[i][j],2));
update(dp[i + 1][j + 1],dp[i][j]);
}
}
out(dp[N][L]);enter;
} int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

【AtCoder】ARC059的更多相关文章

  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. leetcode解题报告(1):Remove Duplicates from Sorted Array

    描述 Given a sorted array, remove the duplicates in place such that each element appear only once and ...

  2. 【线性代数】7-2:线性变化的矩阵(The Matrix of a Linear Transformation)

    title: [线性代数]7-2:线性变化的矩阵(The Matrix of a Linear Transformation) categories: Mathematic Linear Algebr ...

  3. Linux下查看文件和文件夹大小 df,du命令

    转自 http://www.cnblogs.com/benio/archive/2010/10/13/1849946.html df可以查看一级文件夹大小.使用比例.档案系统及其挂入点,但对文件却无能 ...

  4. 经过测试,feign只能通过@RequestBody传对象参数

    通过feign调用,使用ModelAttribute 注解,参数没法传到对应的server

  5. NVMe - NB的特性

    翻译一下,纯粹是为了记住这些特性: NVMe provides the following benefits: ● Ultra-low latency 非常低的延迟 ● Very high throu ...

  6. [crontab]修改默认编辑器

    crontab默认编辑器为nano,超级不好用 想要修改成vim或者其他编辑器,方法如下. sudo select-editor 改为3或者4 再次打开就直接是vim打开了

  7. Oracle 11g win32位 window7下安装教程

    1.首先是去http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html官网下载oracle11 ...

  8. Gevent模块

    前言 如何在使用1个线程的前提下,提网站的并发性,使用协程? 如果要使用协程首先要解决2个问题: 1.如何检测到代码中遇到了IO操作?(XX) 2.如何在线程代码里上下切换?(Greelet模块) 而 ...

  9. springboot之JWT实现权限认证

    1.在pom.xml添加依赖 <dependency> <groupId>com.auth0</groupId> <artifactId>java-jw ...

  10. 阶段5 3.微服务项目【学成在线】_day04 页面静态化_21-页面静态化-静态化测试-静态化程序编写

    public String getPageHtml(String pageId){ /** * 静态化程序获取页面的DataUrl * * 静态化程序远程请求DataUrl获取数据模型 * * 静态化 ...