ARC065

C - 白昼夢 / Daydream

直接递推就好

#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);
}
string s;
int dp[MAXN];
void Solve() {
cin >> s;
dp[0] = 1;
for(int i = 1 ; i <= s.length() ; ++i) {
if(i >= 5) {
dp[i] |= (dp[i - 5] && s.substr(i - 5,5) == "dream");
dp[i] |= (dp[i - 5] && s.substr(i - 5,5) == "erase");
}
if(i >= 6) {
dp[i] |= (dp[i - 6] && s.substr(i - 6,6) == "eraser");
}
if(i >= 7) {
dp[i] |= (dp[i - 7] && s.substr(i - 7,7) == "dreamer");
}
}
if(dp[s.length()]) puts("YES");
else puts("NO");
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

D - 連結 / Connectivity

把图两次染色,然后标号,会得到一个点对,这个点对相同的点才在两个图里都连通

#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 200005
//#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);
}
map<pii,int> zz;
int N,K,L;
int fa[MAXN],col[MAXN][2],tot;
int getfa(int x) {
return fa[x] == x ? x : fa[x] = getfa(fa[x]);
}
void Solve() {
read(N);read(K);read(L);
for(int i = 1 ; i <= N ; ++i) fa[i] = i;
int a,b;
for(int i = 1 ; i <= K ; ++i) {
read(a);read(b);
fa[getfa(a)] = getfa(b);
}
tot = 0;
for(int i = 1 ; i <= N ; ++i) {
if(getfa(i) == i) col[i][0] = ++tot;
}
for(int i = 1 ; i <= N ; ++i) col[i][0] = col[getfa(i)][0];
for(int i = 1 ; i <= N ; ++i) fa[i] = i;
for(int i = 1 ; i <= L ; ++i) {
read(a);read(b);
fa[getfa(a)] = getfa(b);
}
tot = 0;
for(int i = 1 ; i <= N ; ++i) {
if(getfa(i) == i) col[i][1] = ++tot;
}
for(int i = 1 ; i <= N ; ++i) col[i][1] = col[getfa(i)][1];
for(int i = 1 ; i <= N ; ++i) {
zz[mp(col[i][0],col[i][1])]++;
}
for(int i = 1 ; i <= N ; ++i) {
out(zz[mp(col[i][0],col[i][1])]);space;
}
enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

E - へんなコンパス / Manhattan Compass

曼哈顿转切比雪夫

然后把点对排序,每个点用横坐标相连就是

\(x_{a} - x_{b} = D\)

并且$ -D<= y_{a} - y_{b} <= D$

这是一段区间,我们可以把区间里的点两两相连,再和a点相连,是等价的

然后记录每个点连出去的边有多少,和初始的两个点连通的所有点之间的边数加起来就是答案

#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);
}
struct node {
int to,next;
}E[MAXN * 10];
int head[MAXN],sumE;
int N,a,b;
int x[MAXN],y[MAXN],D,id[MAXN],cnt[MAXN];
pii p[MAXN],tmp[MAXN];
int st[MAXN],ed[MAXN];
int fa[MAXN];
int getfa(int x) {
return fa[x] == x ? x : fa[x] = getfa(fa[x]);
}
void Merge(int x,int y) {
fa[getfa(x)] = getfa(y);
}
void AddE(int on) {
for(int i = 1 ; i <= N ; ++i) {
id[i] = i;
}
sort(id + 1,id + N + 1,[](int a,int b){return p[a] < p[b];});
memset(st,0,sizeof(st));memset(ed,0,sizeof(ed)); for(int i = 1 ; i <= N ; ++i) {
tmp[i] = p[id[i]];
}
for(int i = 1 ; i <= N ; ++i) {
int l = lower_bound(tmp + 1,tmp + N + 1,mp(tmp[i].fi + D,tmp[i].se - D + on)) - tmp;
int r = upper_bound(tmp + 1,tmp + N + 1,mp(tmp[i].fi + D,tmp[i].se + D - on)) - tmp - 1;
if(l <= r) {
st[l]++;ed[r]++;
Merge(id[i],id[l]);
cnt[id[i]] += r - l + 1;
}
}
int pre = 0;
for(int i = 1 ; i < N ; ++i) {
pre += st[i];pre -= ed[i];
if(pre) Merge(id[i],id[i + 1]);
}
}
void Solve() {
read(N);read(a);read(b);
for(int i = 1 ; i <= N ; ++i) {
read(x[i]);read(y[i]);
fa[i] = i;
} D = abs(x[a] - x[b]) + abs(y[a] - y[b]);
for(int i = 1 ; i <= N ; ++i) p[i] = mp(x[i] + y[i],x[i] - y[i]);
AddE(0);
for(int i = 1 ; i <= N ; ++i) swap(p[i].fi,p[i].se);
AddE(1);
int64 ans = 0;
for(int i = 1 ; i <= N ; ++i) {
if(getfa(i) == getfa(a)) ans += cnt[i];
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

F - シャッフル / Shuffling

就是对于一个区间,记录能用a个0和b个1

然后对于某个位置填0还是填1

由于能用的数是总和是确定的,我们只要记录当前有a个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 3005
//#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 ri[MAXN],f[2][MAXN];
int N,M;
char s[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(M);
scanf("%s",s + 1);
int l,r;
for(int i = 1 ; i <= M ; ++i) {
read(l);read(r);
ri[l] = max(ri[l],r);
}
int p = 0,all = 0;
int cur = 0;
f[cur][0] = 1; for(int i = 1 ; i <= N ; ++i) {
if(p < i - 1) {p = i - 1;}
if(ri[i] > p) {
all += ri[i] - p;
int a = 0,b = 0;
for(int j = p + 1 ; j <= ri[i] ; ++j) {
if(s[j] == '0') ++a;
else ++b;
}
p = ri[i];
memset(f[cur ^ 1],0,sizeof(f[cur ^ 1]));
for(int j = a ; j <= N ; ++j) f[cur ^ 1][j] = f[cur][j - a];
cur ^= 1;
}
if(!all) continue;
memset(f[cur ^ 1],0,sizeof(f[cur ^ 1]));
for(int j = 0 ; j <= all ; ++j) {
if(j < all) update(f[cur ^ 1][j],f[cur][j]);
if(j >= 1) update(f[cur ^ 1][j - 1],f[cur][j]);
}
--all;
cur ^= 1;
}
out(f[cur][0]);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

【AtCoder】ARC065的更多相关文章

  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. 在Android中使用OpenGL ES进行开发第(二)节:定义图形

    一.前期基础知识储备笔者计划写三篇文章来详细分析OpenGL ES基础的同时也是入门关键的三个点: ①OpenGL ES是什么?与OpenGL的关系是什么?——概念部分 ②使用OpenGLES绘制2D ...

  2. Ubuntu 14.04 网卡网关配置修改

    #添加网关route add default gw 192.168.5.1#强制修改网卡地址ifconfig eth0 192.168.5.40 netmask 255.255.255.0. 服务器需 ...

  3. expdp / impdp 用法详解 ,和exp / imp 的区别

    一  关于expdp和impdp     使用EXPDP和IMPDP时应该注意的事项:EXP和IMP是客户端工具程序,它们既可以在客户端使用,也可以在服务端使用.EXPDP和IMPDP是服务端的工具程 ...

  4. 【spring源码分析】IOC容器初始化——查漏补缺(二)

    前言:在[spring源码分析]IOC容器初始化(八)中多次提到了前置处理与后置处理,本篇文章针对此问题进行分析.Spring对前置处理或后置处理主要通过BeanPostProcessor进行实现. ...

  5. CISCO实验记录十一:switch端口安全配置

    1.启用交换机端口安全 2.限制端口最大访问量为1,超出后关闭端口 1.启用交换机端口安全 #interface gigabitEthernet 0/1 #switchport mode access ...

  6. COM组件双接口对象模型

    模型如下: 这里COM对象一共实现了三个接口,IUnknown,IDispatch, Ixxx. 每个COM都必须实现IUnknown,不考虑在内的话共实现了IDispatch和自定义接口Ixxx两个 ...

  7. Qt configure 参数

    在编译QT前,可加各种参数来定制自己想要的QT库.这对需要裁减QT库的朋友来说非常重要.对于如何编译QT,可以参考:http://hi.baidu.com/agassi%5Fp/blog/item/4 ...

  8. 微信小程序倒计时的方法

    timeOut: function(time) { var that = this; var end = new Date(time).getTime(); var Interval = setInt ...

  9. LightGBM两种使用方式

    原生形式使用lightgbm(import lightgbm as lgb) import lightgbm as lgb from sklearn.metrics import mean_squar ...

  10. 性能分析 | Java服务器内存过高&CPU过高问题排查

    一.内存过高 1.内存过高一般有两种情况:内存溢出和内存泄漏 (1)内存溢出:程序分配的内存超出物理机的内存大小,导致无法继续分配内存,出现OOM报错 (2)内存泄漏:不再使用的对象一直占据着内存不释 ...