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 ivorysifreopen("f1.in","r",stdin);
#endifSolve();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 ivorysifreopen("f1.in","r",stdin);
#endifSolve();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 ivorysifreopen("f1.in","r",stdin);
#endifSolve();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 ivorysifreopen("f1.in","r",stdin);
#endifSolve();return 0;
}

转载于:https://www.cnblogs.com/ivorysi/p/10856672.html

【AtCoder】ARC065相关推荐

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

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

  2. 【Atcoder】ARC083 D - Restoring Road Network

    [算法]图论,最短路? [题意]原图为无向连通图,现给定原图的最短路矩阵,求原图最小边权和,n<=300. [题解]要求最小边权和下,原图的所有边一定是所连两端点的最短路. 那么现在将所有最短路 ...

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

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

  4. 【atcoder】Enclosed Points [abc136F]

    题目传送门:https://atcoder.jp/contests/abc136/tasks/abc136_f 题目大意:在平面上有$n$个点我们,定义一个点集的权值为平面上包含这个点集的最小矩形所包 ...

  5. 【atcoder】GP 2 [agc036C]

    题目传送门:https://atcoder.jp/contests/agc036/tasks/agc036_c 题目大意:给你一个长度为$N$初始全0的序列,每次操作你可以找两个不同的元素,一个自增1 ...

  6. 【AtCoder】AGC034

    AGC034 刷了那么久AtCoder我发现自己还是只会ABCE(手动再见 A - Kenken Race 大意是一个横列,每个点可以跳一步或者跳两步,每个格子是空地或者石头,要求每一步不能走到石头或 ...

  7. 【Atcoder】AtCoder Beginner Contest 174总结

    目录 A Air Conditioner B Distance C Repsept D Alter Altar E Logs F Range Set Query A B C D E F √ √ ● ○ ...

  8. 【AtCoder】ARC088

    C - Multiple Gift 题解 首项是X,每次乘个2,暴力统计 代码 #include <bits/stdc++.h> #define fi first #define se s ...

  9. 【AtCoder】diverta 2019 Programming Contest 2

    diverta 2019 Programming Contest 2 A - Ball Distribution 特判一下一个人的,否则是\(N - (K - 1) - 1\) #include &l ...

  10. 【AtCoder】AGC017

    A - Biscuits dp[i][0/1]表示当前和是偶数还是奇数,直接转移即可 #include <bits/stdc++.h> #define fi first #define s ...

最新文章

  1. redis的导入导出需要特别注意的地方
  2. mysql 线程内存 回收_MySQL内存使用-线程独享
  3. js java自动部署_vue 自动化部署 jenkins 篇
  4. [Vue warn]: Do not use built-in or reserved HTML elements as component id: header
  5. jQuery和MooTools的真正区别
  6. 笔试题??智商题??(一)
  7. 信息学奥赛一本通(1406:单词替换)
  8. vba 数组赋值_VBA数组与字典解决方案第31讲:VBA数组声明及赋值后的回填方法
  9. 用Android Stuidio开发Flutter
  10. js中的forEach
  11. 写给 3 年内程序开发者的一封信
  12. 如何降低 Python 的内存消耗量?
  13. GridView控件RowDataBound事件中获取列字段的几种途径
  14. mybatis3-中文文档
  15. 天使轮、A轮、B轮、C轮、D轮融资 究竟是什么?
  16. jira图片_JIRA issue 中的标记语言(Textile)
  17. python源代码的后缀名是什么_Python
  18. 你应该会喜欢的5个自定义 Hook
  19. 有n个结构体变量,内含学生学号、姓名、3门课程的成绩,要求输出平均成绩最高的学生信息
  20. adb 进入 recovery adb 进入 bootloader

热门文章

  1. Ubuntu 安装hadoop 伪分布式
  2. Shell 批量复制文件名相近的文件到指定文件名中
  3. php中的加密解密模块-mcrypt
  4. (转)详解HTML网页源码的charset格式
  5. HDOJ 1251 HDU 1251 统计难题 ACM 1251 IN HDU
  6. 白话数字签名(1)——基本原理
  7. 入门到 精通 JavaScript中的正则表达式RE、RegExp
  8. formatter function (value,row,index){} 参数的含义
  9. docker自定义网络
  10. gatewayworker配置php,tp5整合GatewayWorker