【AtCoder】ARC094(C-F)题解
C - Same Integers
题解
要么三个都达到最大的数,要么三个都到达最大的数+1,判断是前一种情况的方法是不断垫高前两大的,看之后最小的那个和最大的那个差值是不是2的倍数
否则就是第二种情况
代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>
//#define ivorysi
#define MAXN 100005
#define eps 1e-7
#define mo 974711
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
const int P = 100000;
int a[5];
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
for(int i = 1 ; i <= 3 ; ++i) scanf("%d",&a[i]);
sort(a + 1,a + 4);
if((a[3] - (a[1] + a[3] - a[2])) % 2 == 0) {
printf("%d\n",a[3] - a[2] + (a[3] - (a[1] + a[3] - a[2])) / 2);
}
else {
++a[3];++a[1];
if(a[2] < a[1]) swap(a[2],a[1]);
int cnt = 1 + a[3] - a[2] + (a[3] - (a[1] + a[3] - a[2])) / 2;
printf("%d\n",cnt);
}
}
D - Worst Case
题解
先二分一个答案,然后两两数乘积分个段的话是个二次函数,可以三分求极值
WA了无数次,我实在不知道段该怎么分,我把能分的部分都给取个max,然后过了
代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>
//#define ivorysi
#define MAXN 100005
#define eps 1e-7
#define mo 974711
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
int64 A,B;
int Q;
int64 calc(int64 X,int64 MID) {
int64 s = MID,t = X - MID + 2;
if(s >= A) ++s;
if(t <= B) --t;
return s * t;
}
int64 get_Max(int64 X,int64 L,int64 R) {
while(R - L + 1 >= 3) {
int64 K = (R - L + 1) / 3;
int64 LB = L + K,RB = R - K;
if(calc(X,LB) < calc(X,RB)) L = LB;
else R = RB;
}
int64 ans = 0;
for(int64 i = L ; i <= R ; ++i) ans = max(ans,calc(X,i));
return ans;
}
int64 check(int64 MID) {
int64 res = 0;
res = max(get_Max(MID,1,A - 1),res);
res = max(get_Max(MID,MID - A + 2,MID),res);
res = max(get_Max(MID,1,B - 1),res);
res = max(get_Max(MID,MID - B + 2,MID),res);
res = max(get_Max(MID,A,B),res);
res = max(get_Max(MID,A,MID - B + 2),res);
res = max(get_Max(MID,B,MID - A + 2),res);
return res;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
scanf("%d",&Q);
while(Q--) {
scanf("%lld%lld",&A,&B);
if(A > B) swap(A,B);
int64 P = A * B;
int64 L = 0,R = (A + B);
while(L < R) {
int64 MID = (L + R + 1) >> 1;
if(check(MID) < P) L = MID;
else R = MID - 1;
}
printf("%lld\n",L);
}
}
E - Tozan and Gezan
题解
显然最后会Tozan最后不得不剩下一个A[i] > B[i]且B[i]最小的一块,这是最优的
求个和减去这个B[i]就行
如果都相等就是0
代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>
//#define ivorysi
#define MAXN 200005
#define eps 1e-7
#define mo 974711
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
int64 A[MAXN],B[MAXN],sum;
int N;
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
scanf("%d",&N);
for(int i = 1 ; i <= N ; ++i) scanf("%lld%lld",&A[i],&B[i]);
int64 minn = 0x7fffffff;
for(int i = 1 ; i <= N ; ++i) {
sum += B[i];
if(B[i] < A[i]) minn = min(B[i],minn);
}
if(minn == 0x7fffffff) puts("0");
else printf("%lld\n",sum - minn);
}
F - Normalization
题解
如果s中每个数都相等,那么答案是1
如果s<=3暴搜
之后我们发现如果a = 0,b = 1,c = 2
那么变换后的串和原来的串总和是一样的
而且变换后的串里面一定有两个相邻数字是一样的
如何证明呢,我们把长度为4的情况暴搜一下,发现是对的,然后以后长度的情况就可以把第一个字符改成对的然后删掉第一个字符递归证明
然后用一个dp求出这样的串,同时若没有两个相邻数字是一样的,还要检查一下S本身是不是一个这样的串
代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>
//#define ivorysi
#define MAXN 200005
#define eps 1e-7
#define mo 974711
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
const int64 MOD = 998244353;
int N;
char s[MAXN];
int64 dp[MAXN][3][3][2];
void inc(int64 &x,int64 y) {
x = x + y;
while(x >= MOD) x -= MOD;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
scanf("%s",s + 1);
N = strlen(s + 1);
bool all_same = 1;
for(int i = 1 ; i <= N ; ++i) {
if(s[i] != s[1]) all_same = 0;
}
if(all_same) {puts("1");return 0;}
if(N > 3) {
for(int i = 0 ; i <= 2 ; ++i) dp[1][i][i][0] = 1;
for(int i = 2 ; i <= N ; ++i) {
for(int s = 0 ; s <= 2 ; ++s) {
for(int j = 0 ; j <= 2 ; ++j) {
for(int h = 0 ; h <= 2 ; ++h) {
for(int l = 0 ; l <= 1 ; ++l) {
inc(dp[i][(s + h) % 3][h][l || h == j],dp[i - 1][s][j][l]);
}
}
}
}
}
bool flag = 1;
int c = 0;
for(int i = 1 ; i <= N ; ++i) {
c = (c + s[i] - 'a') % 3;
}
for(int i = 2 ; i <= N ; ++i) {
if(s[i] == s[i - 1]) {flag = 0;break;}
}
int64 ans = flag;
for(int i = 0 ; i <= 2 ; ++i) ans += dp[N][c][i][1];
ans %= MOD;
printf("%lld\n",ans);
}
else {
if(N == 3) {
if(s[1] != s[2] && s[2] != s[3] && s[1] != s[3]) puts("3");
else if(s[1] == s[2] || s[2] == s[3]) puts("6");
else puts("7");
}
else if(N == 2) {
puts("2");
}
}
return 0;
}
【AtCoder】ARC094(C-F)题解的更多相关文章
- AtCoder Beginner Contest 238 A - F 题解
AtCoder Beginner Contest 238 \(A - F\) 题解 A - Exponential or Quadratic 题意 判断 \(2^n > n^2\)是否成立? S ...
- AtCoder ExaWizards 2019 简要题解
AtCoder ExaWizards 2019 简要题解 Tags:题解 link:https://atcoder.jp/contests/exawizards2019 很水的一场ARC啊,随随便便就 ...
- AtCoder Beginner Contest 154 题解
人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...
- AtCoder Beginner Contest 153 题解
目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...
- AtCoder Beginner Contest 177 题解
AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...
- AtCoder Beginner Contest 184 题解
AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...
- AtCoder Beginner Contest 173 题解
AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...
- AtCoder Beginner Contest 172 题解
AtCoder Beginner Contest 172 题解 目录 AtCoder Beginner Contest 172 题解 A - Calc B - Minor Change C - Tsu ...
- AtCoder Beginner Contest 169 题解
AtCoder Beginner Contest 169 题解 这场比赛比较简单,证明我没有咕咕咕的时候到了! A - Multiplication 1 没什么好说的,直接读入两个数输出乘积就好了. ...
- AtCoder Beginner Contest 148 题解
目录 AtCoder Beginner Contest 148 题解 前言 A - Round One 题意 做法 程序 B - Strings with the Same Length 题意 做法 ...
随机推荐
- bzoj千题计划126:bzoj1038: [ZJOI2008]瞭望塔
http://www.lydsy.com/JudgeOnline/problem.php?id=1038 本题可以使用三分法 将点按横坐标排好序后 对于任意相邻两个点连成的线段,瞭望塔的高度 是单峰函 ...
- Eclipse使用小结
一.Eclipse新建工作空间设置默认编码格式UTF-8 1.windows->Preferences...打开"首选项"对话框,左侧导航树,导航到general->W ...
- 是否使用TDD(测试驱动开发)进行UI开发
问题 StackOverflow上有一则是否使用TDD(测试驱动开发)进行UI开发 的提问. _JacobE_问: 对于是否使用TDD进行开发UI这件事,我想了很久,但难以决定.我想听听你们的意见. ...
- 【数据库】SQL经典面试题 - 行列转换二 - 列转行
本帖子是行转列的一个逆向操作——列转行,看下面一个面试题 面试题2: 柠檬班第30期学生要毕业了,他们的Linux.MySQL.Java成绩数据表 tb_lemon_grade_column中, 表中 ...
- python——脚本和print
脚本和print 1.脚本文件 <Python 基础教程>(第二版)中 P118页,原操作为下: 1 _metaclass_ = type 2 3 class Person: 4 def ...
- python 爬虫简单的demo
''' @author :Eric-chen @contact:809512722@qq.com @time :2018/1/3 17:55 @desc :通过爬取http://movie.douba ...
- 【四校联考】【比赛题解】FJ NOIP 四校联考 2017 Round 7
此次比赛为厦门一中出题.都是聚劳,不敢恭维. 莫名爆了个0,究其原因,竟然是快读炸了……很狗,很难受. 话不多说,来看看题: [T1] 题意: 样例: PS:1<=h[i]<=100000 ...
- linux arm的存储分布那些事之一【转】
转自:http://blog.csdn.net/xiaojsj111/article/details/11724081 linux arm的存储分布那些事之一 linux arm 内存分布总览 上图是 ...
- aarch64_o2
opensips-event_rabbitmq-2.2.3-1.fc26.aarch64.rpm 2017-03-10 01:22 42K fedora Mirroring Project opens ...
- TF-搞不懂的TF矩阵加法
看谷歌的demo mnist,卷积后加偏执量的代码 h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1)h_pool1 = max_pool ...