【AtCoder】CODE FESTIVAL 2017 qual A
A - Snuke's favorite YAKINIKU
……
#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 40005
#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);
}
string s;
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
cin >> s;
if(s.substr(0,4) == "YAKI") puts("Yes");
else puts("No");
}
B - fLIP
枚举N有几个按了,M有几列按了
对于一个点,行和列只有一个按了,那么这个点是黑的
#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 40005
#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,M,K;
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
read(N);read(M);read(K);
for(int i = 0 ; i <= N ; ++i) {
for(int j = 0 ; j <= M ; ++j) {
int res = i * (M - j) + (N - i) * j;
if(res == K) {puts("Yes");return 0;}
}
}
puts("No");
return 0;
}
C - Palindromic Matrix
从最外一圈开始推,我们输出需要几个4个一样的,2个一样的,可能还有需要1个单个的
然后用每个字母开始填4个一样的,再填2个一样的,再填1个单个的
如果没填完,那么就构造不出来
#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 40005
#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,M;
int num[30],cnt[10];
char s[105][105];
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
read(N);read(M);
for(int i = 1 ; i <= N ; ++i) {
scanf("%s",s[i] + 1);
}
for(int i = 1 ; i <= N ; ++i) {
for(int j = 1 ; j <= M ; ++j) {
num[s[i][j] - 'a']++;
}
}
int lr = 1,rr = N,lc = 1,rc = M;
while(lr <= rr && lc <= rc) {
int r = 0;
if(lr != rr) r += 2;
if(lc != rc) r += 2;
if(!r) r = 1;
cnt[r]++;
for(int i = 1 ; i <= N ; ++i) {
if(lr + i <= rr - i) {
int r = 0;
if(lr + i != rr - i) r += 2;
if(lc != rc) r += 2;
cnt[r]++;
}
else break;
}
for(int i = 1 ; i <= M ; ++i) {
if(lc + i <= rc - i) {
int r = 0;
if(lc + i != rc - i) r += 2;
if(rr != lr) r += 2;
cnt[r]++;
}
else break;
}
++lr;--rr;++lc;--rc;
}
for(int i = 0 ; i < 26 ; ++i) {
while(cnt[4] && num[i] >= 4) {num[i] -= 4;--cnt[4];}
while(cnt[2] && num[i] >= 2) {num[i] -= 2;--cnt[2];}
while(cnt[1] && num[i] >= 1) {num[i] -= 1;--cnt[1];}
}
if(cnt[1] || cnt[2] || cnt[4]) puts("No");
else puts("Yes");
return 0;
}
D - Four Coloring
把图旋转45度后,再放一个每块大小是d*d的方格,然后一行用RB间隔染色,下一行用GY间隔染色
#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);
}
int H,W,d;
bool vis[1005][1005];
string s = "RBGY";
void Solve() {
read(H);read(W);read(d);
for(int i = 1 ; i <= H ; ++i) {
for(int j = 1 ; j <= W ; ++j) {
int t = 0;
if((i + j - 1) / d & 1) t |= 2;
if((i - j + 500 - 1) / d & 1) t |= 1;
putchar(s[t]);
}
enter;
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}
E - Modern Painting
第一次肯定是一个竖直的完整画下来,或者一个水平的完整的画下来
用竖直的举例
就是枚举一个区间\([L,R]\)都是完整的竖直画下来,方案数是2的这个区间上下都有人的列个数次幂
然后算前后的那一块方案数
肯定是先横着一刀,再竖着一刀,再横着一刀
我们把横着的轮廓线画出来,再把一边的翻过去,发现是一个路径计数,但是要求对称轴必须有一个竖线
加入竖直有X个人,上有Y人,下有Z人,那么如果直接走过去,方案数是
\(\binom{X + Y + Z}{X}\)
那我们考虑一个序列,我们就走\(X - 1\)个竖直的,横向走到对称轴后,紧接着就添加一个竖直的
方案数就是
\(\binom{X + Y + Z - 1}{X - 1}\)就是方案数
#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 200500
#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 = 998244353;
int N,M;
char a[4][MAXN];
int fac[MAXN * 2],invfac[MAXN * 2],f[MAXN],b[MAXN],sum[4][MAXN],s[MAXN];
int pw[MAXN],ipw[MAXN],ans;
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;
}
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;
}
void update(int &x,int y) {
x = inc(x,y);
}
int C(int n,int m) {
if(n < m) return 0;
return mul(fac[n],mul(invfac[m],invfac[n - m]));
}
void CalcV() {
memset(f,0,sizeof(f));
memset(b,0,sizeof(b));
memset(s,0,sizeof(s));
int X = sum[0][N],Y,Z;
for(int i = 0 ; i <= M ; ++i) {
if(a[2][i + 1] == '0' && a[3][i + 1] == '0') continue;
Y = sum[2][i],Z = sum[3][i];
if(!X) {
if(Y == 0 && Z == 0) f[i] = 1;
else f[i] = 0;
}
else {
f[i] = C(X + Y + Z - 1,X - 1);
}
}
X = sum[1][N];
for(int i = M + 1 ; i >= 1 ; --i) {
if(a[2][i - 1] == '0' && a[3][i - 1] == '0') continue;
Y = sum[2][M] - sum[2][i - 1],Z = sum[3][M] - sum[3][i - 1];
if(!X) {
if(Y == 0 && Z == 0) b[i] = 1;
else b[i] = 0;
}
else {
b[i] = C(X + Y + Z - 1,X - 1);
}
}
for(int i = 1 ; i <= M ; ++i) s[i] = s[i - 1] + (a[2][i] == '1' && a[3][i] == '1');
for(int i = 0 ; i <= M ; ++i) {
f[i] = mul(f[i],ipw[s[i]]);
}
for(int i = M + 1 ; i >= 1 ; --i) {
b[i] = inc(b[i + 1],mul(b[i],pw[s[i - 1]]));
}
for(int i = 1 ; i <= M ; ++i) {
update(ans,mul(f[i - 1],b[i + 1]));
}
}
void CalcH() {
memset(f,0,sizeof(f));
memset(b,0,sizeof(b));
memset(s,0,sizeof(s));
int X = sum[2][M],Y,Z;
for(int i = 0 ; i <= N ; ++i) {
if(a[0][i + 1] == '0' && a[1][i + 1] == '0') continue;
Y = sum[0][i],Z = sum[1][i];
if(!X) {
if(Y == 0 && Z == 0) f[i] = 1;
else f[i] = 0;
}
else {
f[i] = C(X + Y + Z - 1,X - 1);
}
}
X = sum[3][M];
for(int i = N + 1 ; i >= 1 ; --i) {
if(a[0][i - 1] == '0' && a[1][i - 1] == '0') continue;
Y = sum[0][N] - sum[0][i - 1],Z = sum[1][N] - sum[1][i - 1];
if(!X) {
if(Y == 0 && Z == 0) b[i] = 1;
else b[i] = 0;
}
else {
b[i] = C(X + Y + Z - 1,X - 1);
}
}
for(int i = 1 ; i <= N ; ++i) s[i] = s[i - 1] + (a[0][i] == '1' && a[1][i] == '1');
for(int i = 0 ; i <= N ; ++i) {
f[i] = mul(f[i],ipw[s[i]]);
}
for(int i = N + 1 ; i >= 1 ; --i) {
b[i] = inc(b[i + 1],mul(b[i],pw[s[i - 1]]));
}
for(int i = 1 ; i <= N ; i++) {
update(ans,mul(f[i - 1],b[i + 1]));
}
}
void Solve() {
read(N);read(M);
for(int i = 0 ; i <= 3 ; ++i) scanf("%s",a[i] + 1);
for(int i = 0 ; i <= 3 ; ++i) {
int T = (i <= 1 ? N : M);
for(int j = 1 ; j <= T ; ++j) {
sum[i][j] = sum[i][j - 1] + (a[i][j] == '1');
}
}
int T = 2 * (N + M) + 10;
fac[0] = 1;
for(int i = 1 ; i <= T ; ++i) {
fac[i] = mul(fac[i - 1],i);
}
invfac[T] = fpow(fac[T],MOD - 2);
for(int i = T - 1 ; i >= 0 ; --i) {
invfac[i] = mul(invfac[i + 1],i + 1);
}
pw[0] = 1;
T = max(N,M);
for(int i = 1 ; i <= T ; ++i) {
pw[i] = mul(pw[i - 1],2);
}
ipw[0] = 1;
for(int i = 1 ; i <= T ; ++i) {
ipw[i] = mul(ipw[i - 1],(MOD + 1) / 2);
}
CalcV();
CalcH();
if(!sum[0][N] && !sum[1][N] && !sum[2][M] && !sum[3][M]) ans = 1;
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}
F - Squeezing Slimes
对于一个单个的区间来说,我们可以用
如果\(a = 2^{k}\)能用k次合成
如果\(2^{k} < a < 2^{k + 1}\),能用k+1次合成
我们记录一下每个区间最左的元素被选了几次,最右的区间选了几次
如果是\(a = 2^{k}\),那么两边就选了k次
另一种有两个情况,左边k次右边k+1次,左边k+1次右边k次
每个相邻的地方可以减少\(min(r_{i},l_{i + 1})\)
用一个dp实现就行
#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;
int a[MAXN],cnt[MAXN],val[MAXN][2];
int64 dp[MAXN][2];
void Solve() {
read(N);
for(int i = 1 ; i <= N ; ++i) {
read(a[i]);
int k = -1,x = a[i];
while(x) {++k;x >>= 1;}
cnt[i] = k;
}
for(int i = 1 ; i <= N ; ++i) {
dp[i][0] = 1e16;dp[i][1] = 1e16;
int s = cnt[i],t = cnt[i];
if(a[i] != (1 << cnt[i])) ++t;
val[i][0] = s;val[i][1] = t;
for(int j = 0 ; j <= 1 ; ++j) {
dp[i][0] = min(dp[i][0],dp[i - 1][j] + t - min(t,val[i - 1][j]));
dp[i][1] = min(dp[i][1],dp[i - 1][j] + t - min(s,val[i - 1][j]));
}
}
out(min(dp[N][0],dp[N][1]));enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}
【AtCoder】CODE FESTIVAL 2017 qual A的更多相关文章
- 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring
[题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...
- 【Atcoder】CODE FESTIVAL 2017 qual C D - Yet Another Palindrome Partitioning
[题意]给定只含小写字母的字符串,要求分割成若干段使段内字母重组顺序后能得到回文串,求最少分割段数.n<=2*10^5 [算法]DP [题解]关键在于快速判断一个字符子串是否合法,容易发现合法仅 ...
- 【AtCoder】CODE FESTIVAL 2017 qual B
最近不知道为啥被安利了饥荒,但是不能再玩物丧志了,不能颓了 饥荒真好玩 A - XXFESTIVAL CCFESTIVAL #include <bits/stdc++.h> #define ...
- 【AtCoder】CODE FESTIVAL 2017 qual C
A - Can you get AC? No #include <bits/stdc++.h> #define fi first #define se second #define pii ...
- 【AtCoder】CODE FESTIVAL 2016 qual A
CODE FESTIVAL 2016 qual A A - CODEFESTIVAL 2016 -- #include <bits/stdc++.h> #define fi first # ...
- 【AtCoder】CODE FESTIVAL 2016 qual B
CODE FESTIVAL 2016 qual B A - Signboard -- #include <bits/stdc++.h> #define fi first #define s ...
- 【AtCoder】CODE FESTIVAL 2016 qual C
CODE FESTIVAL 2016 qual C A - CF -- #include <bits/stdc++.h> #define fi first #define se secon ...
- 【AtCoder】CODE FESTIVAL 2017 Final
A - AKIBA 模拟即可 代码 #include <bits/stdc++.h> #define fi first #define se second #define pii pair ...
- CODE FESTIVAL 2017 qual B B - Problem Set【水题,stl map】
CODE FESTIVAL 2017 qual B B - Problem Set 确实水题,但当时没想到map,用sort后逐个比较解决的,感觉麻烦些,虽然效率高很多.map确实好写点. 用map: ...
随机推荐
- Mybatis中的StatementType
原文:http://luoyu-ds.iteye.com/blog/1517607 要实现动态传入表名.列名,需要做如下修改 添加属性statementType=”STATEMENT” 同时sql里的 ...
- 2018秋寒假作业6- -PTA编程总结3
PTA3抓老鼠啊~亏了还是赚了?思路: 首先定义变量并初始化为零,然后用if-else语句判断其关系和计算奶酪数量及盈利情况.
- Sqoop入门
1 下载地址 http://archive.cloudera.com/cdh5/cdh/5/ 版本 sqoop-1.4.6-cdh5.7.0 安装包 ...
- oracle_使用子查询创建表
create table emp_bk as (select * from emp where 1=2);这句就是复制源表的结构
- ubuntu下安装搜狗输入法以及出现不能输入中文的解决办法
1. 官网下载安装包 http://pinyin.sogou.com/linux/?r=pinyin 下载你需要的版本,这里选择64位版. 2. 进入软件中心安装 3. 修改ibus为fcitx im ...
- 【逆向工具】IDA使用1-VS2015版本debug查找Main函数,加载符号文件
IDA 常见操作 空格,切换反汇编视图 选择CALL或是跳转 进入函数内部或是跳转处 返回键 ESC daq.exe 分析32位程序 ,生成的IDA数据库文件是 .idb Idap64.exe 分析6 ...
- System.Runtime.InteropServices.COMException (0x800A03EC): 无法访问文件
使用Microsoft.Office.Interop.Excel 操作 今天在服务器部署,操作程序csv文件转xsl文件的时候,遇到一下问题: System.Runtime.InteropServic ...
- WordCloud词云包的安装
1,下载 https://www.lfd.uci.edu/~gohlke/pythonlibs/#wordcloud 2,安装 (window环境安装) 找的下载文件的路径 安装 pip instal ...
- centos7.2环境中kettle环境搭建及任务推送配置详解
目标:将mysql5.5中testdb1的ehr_user表推送到tdoa的ehr_user表中,为避免不必要的麻烦,两张表结构.编码,包括数据库编码保持一致 操作系统:centos7.2 kettl ...
- 关于ftp上传changeWorkingDirectory()方法的路径切换问题
在上传时 FTPClient提供了upload方法,对于upload(file,path)的第二个参数path ,上传到哪里的这个路径, ftp是利用changeWorkingDirectory()方 ...