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. JS知识整理之 Call&Apply方法

    JavaScript中的函数也是对象,和其他JS对象一样也可以包含方法,其中Call和Apply就是其中比较重要的方法,可以用来间接的调用函数.这两个方法允许显式制定调用所需的this值,也就是说所有 ...

  2. 19. SpringBoot_web开发-使用外部Servlet容器&JSP支持

    還沒有web.xml,生  配置tomcat 嵌入式Servlet容器:应用打成可执行的jar 优点:简单.便携: 缺点:默认不支持JSP.优化定制比较复杂 使用定制器[ServerPropertie ...

  3. mysql 查询优化案例汇总

    一 简介:此文章为经历过的sql案例集合和相关思路 二 案例1: 现象: 测试环境出现select语句,join2张表多次join,explain结果如下 出现 using where,using j ...

  4. ROS 多台计算机联网控制机器人

    0. 时间同步 sudo apt-get install chrony 1. ubuntu自带的有openssh-client 可以通过如下指令 ssh username@host 来连接同一局域网内 ...

  5. python3之redis

    1.redis简介 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(s ...

  6. Python3 configparse模块(配置)

    ConfigParser模块在python中是用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(section),每个节可以有多个参数(键=值). 注意:在 ...

  7. MySQL基于LVM快照的备份恢复(临时)

    目录1.数据库全备份2.准备LVM卷3.数据恢复到LVM卷4.基于LVM快照备份数据5.数据灾难恢复6.总结 写在前面:测试环境中已安装有mysql 5.5.36数据库,但数据目录没有存放在LVM卷, ...

  8. nodejs 使用mysql 进行查询的问题

    因为返回的是个对象 var selectSql1="select * from spc_word_mst where WORD_ID=? limit 0,1 "var select ...

  9. CentOS如何设置终端显示字符界面区域的大小

    红框内的文字本应该在上一行后方,调了stty也不行, stty size的值变化,但显示还是没变化 后来参考http://www.jb51.net/os/RedHat/522217.html 修改 / ...

  10. VC++常用数据类型

    原文地址:https://www.cnblogs.com/yincheng01/archive/2008/12/31/2213386.html 一.              VC常用数据类型列表 二 ...