【AtCoder】ARC089
C - Traveling
先看能不能走到,再看看奇偶性是否相同
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
res = 0;char c = getchar();T f = 1;
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;
void Solve() {
int pt,px,py;
int t,x,y;
read(N);
pt = 0,px = 0,py = 0;
for(int i = 1 ; i <= N ; ++i) {
read(t);read(x);read(y);
int k = abs(x - px) + abs(y - py);
if(k > t - pt) {
puts("No");return;
}
if((k ^ t) & 1) {puts("No");return;}
}
puts("Yes");
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
D - Checker
我们计算右下角在\((-2k,-2k)\)到\((-1,-1)\)这个区域内,每个点所在的格子的颜色
发现根据右下角的位置会分成九个小块,把九个小块里的颜色和需求一样的矩阵用差分矩阵加,最后统计前缀和中最大的即可
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
res = 0;char c = getchar();T f = 1;
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,K;
int a[2005][2005];
int dx[5],dy[5];
void add(int x1,int y1,int x2,int y2) {
if(x1 > x2 || y1 > y2) return;
a[x1][y1]++;a[x2 + 1][y2 + 1]++;
a[x1][y2 + 1]--;a[x2 + 1][y1]--;
}
void Solve() {
read(N);read(K);
int x,y;char c[5];
for(int i = 1 ; i <= N ; ++i) {
read(x);read(y);scanf("%s",c + 1);
++x;++y;
int tx = x % K,ty = y % K;
int now = ((x / K) ^ (y / K)) & 1,u;
if(c[1] == 'W') u = 0;
else u = 1;
dx[1] = K - tx,dx[2] = K,dx[3] = tx;
dy[1] = K - ty,dy[2] = K,dy[3] = ty;
for(int i = 1 ; i <= 3 ; ++i) dx[i] += dx[i - 1],dy[i] += dy[i - 1];
for(int h = 1 ; h <= 3 ; ++h) {
for(int t = 1 ; t <= 3 ; ++t) {
int w = (h ^ t ^ now) & 1;
if(w == u) {
add(dx[h - 1] + 1,dy[t - 1] + 1,dx[h],dy[t]);
}
}
}
}
int ans = 0;
for(int i = 1 ; i <= 2 * K ; ++i) {
for(int j = 1 ; j <= 2 * K ; ++j) {
a[i][j] = a[i][j] + a[i][j - 1] + a[i - 1][j] - a[i - 1][j - 1];
ans = max(ans,a[i][j]);
}
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
E - GraphXY
显然\(ax + by + f(a,b) >= d(x,y)\)
\(a\)最多100个\(b\)最多100个,可以都构建出来
然后对于每个\((a,b)\)求出来\(f(a,b)\)
最后再对于每个\(x,y\)判一遍\(d(x,y)\)是否合法
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
res = 0;char c = getchar();T f = 1;
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 A,B;
int d[15][15];
int f[105][105],tot,gx[105],gy[105],S,T;
pii p[305 * 305];
int val[305 * 305],cnt;
int check(int x,int y) {
int res = 1000000;
for(int i = 0 ; i <= 100 ; ++i) {
for(int j = 0 ; j <= 100 ; ++j) {
res = min(res,f[i][j] + i * x + j * y);
}
}
return res;
}
void Solve() {
read(A);read(B);
for(int i = 1 ; i <= A ; ++i) {
for(int j = 1 ; j <= B ; ++j) {
read(d[i][j]);
}
}
for(int i = 0 ; i <= 100 ; ++i) {
for(int j = 0 ; j <= 100 ; ++j) {
for(int k = 1 ; k <= A ; ++k) {
for(int h = 1 ; h <= B ; ++h) {
f[i][j] = max(f[i][j],d[k][h] - k * i - h * j);
}
}
}
}
for(int i = 1 ; i <= A ; ++i) {
for(int j = 1 ; j <= B ; ++j) {
if(check(i,j) != d[i][j]) {
puts("Impossible");
return;
}
}
}
puts("Possible");
S = ++tot;
gx[0] = S;
for(int i = 1 ; i <= 100 ; ++i) {
gx[i] = ++tot;
p[++cnt] = mp(gx[i - 1],gx[i]);
val[cnt] = -2;
}
T = ++tot;
gy[0] = T;
for(int i = 1 ; i <= 100 ; ++i) {
gy[i] = ++tot;
p[++cnt] = mp(gy[i],gy[i - 1]);
val[cnt] = -1;
}
for(int i = 0 ; i <= 100 ; ++i) {
for(int j = 0 ; j <= 100 ; ++j) {
p[++cnt] = mp(gx[i],gy[j]);
val[cnt] = f[i][j];
}
}
out(tot);space;out(cnt);enter;
for(int i = 1 ; i <= cnt ; ++i) {
out(p[i].fi);space;out(p[i].se);space;
if(val[i] < 0) {
if(val[i] == -2) {puts("X");}
else puts("Y");
}
else {out(val[i]);enter;}
}
out(S);space;out(T);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
F - ColoringBalls
本来以为是个dp没想到是个搜索加剪枝,迷的很。。然而就是搜索我都写跪了……菜的要死QAQ
我们对于白块分成的每一个小块进行分组
然后把相邻的同颜色合起来,比如说RRBBRR变成RBR
然后我们根据所需要达到的最小操作次数来分组
1次操作 r R
2次操作 rb B BR RB BRB
3次操作 rb? BRB RBRB BRBR RBRBR
4次操作 rb?? BRBRB RBRBRB BRBRBR RBRBRBR
问号表示可以任意一种操作
然后对于一种序列,我们可以把必须要填的位置填上,然后挖上几个坑,往里扔数,方案数就是组合数了
例如序列 2 2 3
我们必须要填的是
BWBWBRB
然后挖的坑是
W/R/B/R/W/R/B/R/W/R/B/R/B/R/W
往坑里扔数就行
怎么判断一个序列合不合法,找出所有的r以及它们最靠左没有被搭配过的b,从后往前枚举r,从小到大枚举所需要操作序列长度,对于一个b加上我后面需要用的位置的个数,统计一个后缀和看看合不合法即可
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 1000005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
res = 0;char c = getchar();T f = 1;
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,C[1005][1005],L[75],fac[1005],invfac[1005],cnt;
int sum[75],pos[75],tot,ans,matc[75];
char s[75];
bool vis[75];
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;
}
bool check() {
if(tot < cnt) return false;
memset(sum,0,sizeof(sum));
int p = 1;
for(int i = cnt ; i >= 1 ; --i) {
sum[pos[i]]++;
if(L[p] >= 2) {
if(!matc[pos[i]]) return false;
sum[matc[pos[i]]] += L[p] - 1;
}
++p;
}
for(int i = K ; i >= 1 ; --i) {
sum[i] += sum[i + 1];
if(sum[i] > K - i + 1) return false;
}
return true;
}
bool dfs(int pre,int dep,int len) {
cnt = dep;
if(!check()) return false;
int k = 1 + cnt;
for(int i = 1 ; i <= cnt ; ++i) {
if(L[i] == 1) ++k;
else k += 2 * L[i] - 1;
}
int res = C[N - len + k - 1][k - 1];
res = mul(res,fac[cnt]);
int t = 0;
for(int i = 1 ; i <= cnt ; ++i) {
if(L[i] != L[i - 1]) {
res = mul(res,invfac[t]);
t = 0;
}
++t;
}
res = mul(res,invfac[t]);
update(ans,res);
if(dep + 1 > tot) return true;
for(int i = pre ; i <= 70 ; ++i) {
int tl = len;
if(dep != 0) ++tl;
if(i == 1 || i == 2) tl += 1;
else tl += i - 2 + i - 1;
if(tl > N) break;
L[dep + 1] = i;
if(!dfs(i,dep + 1,tl)) break;
}
return true;
}
void Solve() {
read(N);read(K);
scanf("%s",s + 1);
C[0][0] = 1;
for(int i = 1 ; i <= 1000 ; ++i) {
C[i][0] = 1;
for(int j = 1 ; j <= i ; ++j) {
C[i][j] = inc(C[i - 1][j - 1],C[i - 1][j]);
}
}
fac[0] = 1;
for(int i = 1 ; i <= 1000 ; ++i) fac[i] = mul(fac[i - 1],i);
invfac[1000] = fpow(fac[1000],MOD - 2);
for(int i = 999 ; i >= 0 ; --i) invfac[i] = mul(invfac[i + 1],i + 1);
tot = 0;
for(int i = 1 ; i <= K ; ++i) {
if(s[i] == 'r') {
pos[++tot] = i;
for(int j = i + 1 ; j <= K ; ++j) {
if(s[j] == 'b' && !vis[j]) {matc[i] = j;vis[j] = 1;break;}
}
}
}
dfs(1,0,0);
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
【AtCoder】ARC089的更多相关文章
- 【AtCoder】ARC092 D - Two Sequences
[题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...
- 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring
[题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...
- 【AtCoder】ARC 081 E - Don't Be a Subsequence
[题意]给定长度为n(<=2*10^5)的字符串,求最短的字典序最小的非子序列字符串. http://arc081.contest.atcoder.jp/tasks/arc081_c [算法]字 ...
- 【AtCoder】AGC022 F - Leftmost Ball 计数DP
[题目]F - Leftmost Ball [题意]给定n种颜色的球各k个,每次以任意顺序排列所有球并将每种颜色最左端的球染成颜色0,求有多少种不同的颜色排列.n,k<=2000. [算法]计数 ...
- 【AtCoder】AGC005 F - Many Easy Problems 排列组合+NTT
[题目]F - Many Easy Problems [题意]给定n个点的树,定义S为大小为k的点集,则f(S)为最小的包含点集S的连通块大小,求k=1~n时的所有点集f(S)的和取模92484403 ...
- 【AtCoder】ARC067 F - Yakiniku Restaurants 单调栈+矩阵差分
[题目]F - Yakiniku Restaurants [题意]给定n和m,有n个饭店和m张票,给出Ai表示从饭店i到i+1的距离,给出矩阵B(i,j)表示在第i家饭店使用票j的收益,求任选起点和终 ...
- 【AtCoder】ARC095 E - Symmetric Grid 模拟
[题目]E - Symmetric Grid [题意]给定n*m的小写字母矩阵,求是否能通过若干行互换和列互换使得矩阵中心对称.n,m<=12. [算法]模拟 [题解]首先行列操作独立,如果已确 ...
- 【Atcoder】AGC022 C - Remainder Game 搜索
[题目]C - Remainder Game [题意]给定n个数字的序列A,每次可以选择一个数字k并选择一些数字对k取模,花费2^k的代价.要求最终变成序列B,求最小代价或无解.n<=50,0& ...
- 【Atcoder】AGC 020 B - Ice Rink Game 递推
[题意]n个人进行游戏,每轮只保留最大的a[i]倍数的人,最后一轮过后剩余2人,求最小和最大的n,或-1.n<=10^5. [算法]递推||二分 [题解]令L(i),R(i)表示第i轮过后的最小 ...
随机推荐
- 【刷题】BZOJ 4078 [Wf2014]Metal Processing Plant
Description 定义集合S的价值D(S)为: 现在给你n个元素,并给出其中任意两个元素之间的d(i,j)值 要你将这些元素划分成两个集合A.B. 求min{D(A)+D(B)}. 注:d(i, ...
- debian9部署ownCloud
ownCloud是一个开源的私有云存储,支持外接存储,具有良好的扩展性.ownCloud是传统的C/S架构,支持目前各大流行平台.服务端客户端实时同步,使用体验非常好. ownCloud is Wed ...
- NOIP2017 列队——动态开点线段树
Description: Sylvia 是一个热爱学习的女♂孩子. 前段时间,Sylvia 参加了学校的军训.众所周知,军训的时候需要站方阵. Sylvia 所在的方阵中有n×m名学生,方阵的行数为 ...
- 浅谈移动端 View 的显示过程
作者:个推安卓开发工程师 一七 随着科技的发展,各种移动端早已成为人们日常生活中不可或缺的部分,人们使用移动端产品工作.社交.娱乐……移动端界面的流畅性已经成为影响用户体验的重要因素之一.那么你是否思 ...
- Jenkins + Pipeline 构建流水线发布
Jenkins + Pipeline 构建流水线发布 利用Jenkins的Pipeline配置发布流水线 参考: https://jenkins.io/doc/pipeline/tour/depl ...
- JDBC编程示例
package com.lovo.test; import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLE ...
- python---基础知识回顾(一)(引用计数,深浅拷贝,列表推导式,lambda表达式,命名空间,函数参数逆收集,内置函数,hasattr...)
一:列表和元组(引用计数了解,深浅拷贝了解) 序列:序列是一种数据结构,对其中的元素按顺序进行了编号(从0开始).典型的序列包括了列表,字符串,和元组 列表是可变的(可以进行修改),而元组和字符串是不 ...
- list里面放的实体对象,页面用c:foreach应该怎么取?
关于网友提出的" list里面放的实体对象,页面用c:foreach应该怎么取?"问题疑问,本网通过在网上对" list里面放的实体对象,页面用c:foreach应该怎么 ...
- Mac下配置环境变量重启后不生效解决(.bash_profile vs .bashrc)(bash/zsh下不加载.bashrc问题解决)
参考上一篇文章说明:http://www.cnblogs.com/EasonJim/p/6283094.html 得知加载顺序如下: /etc/profile /etc/paths ~/.bash_p ...
- HDU 3371 Connect the Cities 最小生成树(和关于sort和qsort的一些小发现)
解题报告:有n个点,然后有m条可以添加的边,然后有一个k输入,表示一开始已经有k个集合的点,每个集合的点表示现在已经是连通的了. 还是用并查集加克鲁斯卡尔.只是在输入已经连通的集合的时候,通过并查集将 ...