C - Make a Rectangle

每次取两个相同的且最大的边,取两次即可

#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 MAXN 100005
#define eps 1e-12
//#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,a[MAXN];
map<int,int> zz;
void Solve() {
read(N);
for(int i = 1 ; i <= N ; ++i) {read(a[i]);zz[a[i]]++;}
int r = 0,c = 0;
while(1) {
if(zz.empty()) break;
auto t = *(--zz.end());zz.erase(--zz.end());
if(t.se >= 2) {
if(!r) r = t.fi;
else if(!c) c = t.fi;
}
if(t.se > 2) zz[t.fi] = t.se - 2;
if(r && c) break;
}
out(1LL * r * c);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

D - Coloring Dominoes

就是如果是

竖条对两个长条,那么方案数乘上2

竖条对竖条,乘上2

两个长条+竖条,方案数乘上1

两个长条+两个长条 有3种

1 2

2 1



1 3

2 1



1 2

2 3

初始如果一个竖条有3种,两个横条有6种

#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 MAXN 100005
#define eps 1e-12
//#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,f[65];
char s[2][65];
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 Solve() {
read(N);
scanf("%s%s",s[0] + 1,s[1] + 1);
int ans = 0;
for(int i = 1 ; i <= N ; ++i) {
if(s[0][i] == s[0][i + 1]) continue;
if(s[0][i - 1] == s[0][i]) {
if(i <= 2) ans = 6;
else {
if(f[i - 2] == 0) ans = mul(ans,3);
else if(f[i - 2] == 1) ans = mul(ans,2);
}
f[i] = 0;
}
else {
if(i <= 1) ans = 3;
else {
if(f[i - 1] == 1) ans = mul(ans,2);
}
f[i] = 1;
}
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

E - Don't Be a Subsequence

撞题了吧,最短不公共子串的那个模板大礼包

直接建序列自动机,求最短路,每次从前往后遍历走一条最短路边

#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 MAXN 200005
#define eps 1e-12
//#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 a[MAXN];
int nxt[MAXN][26],N,dis[MAXN];
string ans = "";
void Solve() {
scanf("%s",a + 1);
N = strlen(a + 1);
for(int i = 0 ; i < 26 ; ++i) nxt[N][i] = N + 1;
for(int i = N - 1 ; i >= 0 ; --i) {
for(int j = 0 ; j < 26 ; ++j) nxt[i][j] = nxt[i + 1][j];
nxt[i][a[i + 1] - 'a'] = i + 1;
}
dis[N + 1] = 0;
for(int i = N ; i >= 0 ; --i) {
dis[i] = N + 1;
for(int j = 0 ; j < 26 ; ++j) dis[i] = min(dis[nxt[i][j]] + 1,dis[i]);
}
int pos = 0;
while(pos != N + 1) {
for(int i = 0 ; i < 26 ; ++i) {
if(dis[nxt[pos][i]] + 1 == dis[pos]) {
ans += (i + 'a');
pos = nxt[pos][i];
break;
}
}
}
cout << ans << endl;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

F - Flip and Rectangles

我们认为一个长方形任意一个22的方格如果包含偶数个黑点

那么一定会变成全黑

我们把每个2
2的方格中间标记成一个新点,判断能否选择,然后用最大子矩形的算法做

#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 MAXN 2005
#define eps 1e-12
//#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 H,W,ans;
char s[MAXN][MAXN];
int tr[MAXN],tl[MAXN],h[MAXN],l[MAXN],r[MAXN];
bool check(int x,int y) {
return ((s[x - 1][y - 1] == '#') + (s[x - 1][y] == '#') + (s[x][y - 1] == '#') + (s[x][y] == '#')) & 1;
}
void Solve() {
read(H);read(W);
ans = max(H,W);
for(int i = 0 ; i < H ; ++i) {
scanf("%s",s[i]);
}
for(int i = 1 ; i <= W - 1; ++i) l[i] = 0,r[i] = W;
tr[W] = W;
for(int i = 1 ; i < H ; ++i) {
for(int j = 1 ; j < W ; ++j) {
if(check(i,j)) tl[j] = j;
else tl[j] = tl[j - 1];
}
for(int j = W - 1 ; j >= 1 ; --j) {
if(check(i,j)) tr[j] = j;
else tr[j] = tr[j + 1];
}
for(int j = 1 ; j < W ; ++j) {
if(check(i,j)) {
h[j] = 0,l[j] = 0,r[j] = W;
}
else {
l[j] = max(tl[j],l[j]);
r[j] = min(tr[j],r[j]);
h[j]++;
ans = max(ans,(r[j] - l[j] - 1 + 1) * (h[j] + 1));
}
}
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

【AtCoder】ARC081的更多相关文章

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

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

  2. 【AtCoder】ARC092 D - Two Sequences

    [题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...

  3. 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring

    [题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...

  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. C# 比较不错的拓扑图控件

    群内有下载 616945527

  2. 四、NAND Flash

    4.1 nand flash启动u-boot nand flash 启动的时候,CPU 需要将 nand flash 中前面 4KB 的内容复制到 SRAM 中执行,然后将 NAND Flash 中的 ...

  3. Pytorch中的squeeze()和unsqueeze()函数

    在numpy库中,经常会出现“秩为1的一维数组”(come from 吴恩达的深度学习,目前还没有搞清楚numpy中如此设计的意图).比如: 注意这里的a的shape是[3] ,既不是 [1,3] 也 ...

  4. 近几年杭电OJ大型比赛题目合集【更新到2017年11月初】

    2017年: 区域赛网络赛   6194~6205    6206~6216 区域赛网络赛   6217~6229 2016年: 区域赛网络赛  5868~5877    5878~5891    5 ...

  5. POJ1251 Jungle Roads【最小生成树】

    题意: 首先给你一个图,需要你求出最小生成树,首先输入n个节点,用大写字母表示各节点,接着说有几个点和它相连,然后给出节点与节点之间的权值.拿第二个样例举例:比如有3个节点,然后接下来有3-1行表示了 ...

  6. javascript方法--bind()

    bind方法,顾名思义,就是绑定的意思,到底是怎么绑定然后怎么用呢,下面就来说说我对这个方法的理解. 语法 fun.bind(this,arg1,arg2,...) bind()方法会创建一个新的函数 ...

  7. 【python】pip安装报错UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 7: ordinal not in range(128)

    刚安装完python,准备pip安装第三方库的时候出现了一个错误: UnicodeDecodeError: ‘ascii’ code can’t decode byte 0xef in positio ...

  8. POI导出带格式的Excel模板——(六)

    Jar包

  9. 【转】Python之列表生成式、生成器、可迭代对象与迭代器

    [转]Python之列表生成式.生成器.可迭代对象与迭代器 本节内容 语法糖的概念 列表生成式 生成器(Generator) 可迭代对象(Iterable) 迭代器(Iterator) Iterabl ...

  10. passwd: Have exhausted maximum number of retries for service【转】

    使用命令passwd修改密码时,遇到如下问题: # echo 'utf8'|passwd zhangsan --stdin Changing password for user zhangsan. p ...