Codeforces Round #277.5 解题报告
又熬夜刷了cf,今天比正常多一题。比赛还没完但我知道F过不了了,一个半小时贡献给F还是没过……应该也没人Hack。写写解题报告吧= =。
解题报告例如以下:
A题:选择排序直接搞,由于不要求最优交换次数,代码:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <memory.h>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring> using namespace std; #define Clear(f, nr) memset(f, nr, sizeof(f))
const int SIZE = 3001;
const int MSIZE = 10000;
const int INF = 1 << 30;
typedef long long ll;
pair<int, int> p[SIZE]; int main() {
int n;
int a[SIZE];
while(cin >> n) {
for(int i = 0; i < n; i ++)
cin >> a[i];
int k = 0;
for(int i = 0; i < n - 1; i ++) {
int Mi = a[i];
int mark = i;
for(int j = i + 1; j < n; j ++) {
if(a[j] < Mi) {
Mi = a[j];
mark = j;
}
}
if(mark != i) {
swap(a[i], a[mark]);
p[k ++] = make_pair(i, mark);
}
}
cout << k << endl;
for(int i = 0; i < k; i ++)
cout << p[i].first << " " << p[i].second << endl;
}
}
B题:贪心思想,排序后从小到大匹配就可以:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <memory.h>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring> using namespace std; #define Clear(f, nr) memset(f, nr, sizeof(f))
const int SIZE = 500;
const int MSIZE = 10000;
const int INF = 1 << 30;
typedef long long ll; int main() {
int n, m;
int a[SIZE], b[SIZE];
while(cin >> n) {
for(int i = 0; i < n; i ++)
cin >> a[i];
cin >> m;
for(int i = 0; i < m; i ++)
cin >> b[i];
sort(a, a + n);
sort(b, b + m);
int sum = 0;
bool vis[SIZE];
Clear(vis, 0);
for(int i = 0; i < n; i ++) {
for(int j = 0; j < m; j ++) {
if(!vis[j] && abs(a[i] - b[j]) <= 1) {
vis[j] = 1;
sum ++;
break;
}
}
}
cout << sum << endl;
}
}
C题:贪心思想。假设是最小值,除去第一位尽可能放0。第一位尽可能放1。同理,最大值尽可能放9
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <memory.h>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring> using namespace std; #define Clear(f, nr) memset(f, nr, sizeof(f))
const int SIZE = 500;
const int MSIZE = 10000;
const int INF = 1 << 30;
typedef long long ll; string gMi(int m, int s) {
string ans;
int tmp = s - 9 * (m - 1);
if(tmp <= 0) {
ans += '1';
s -= 1;
}
else {
ans += tmp + '0';
s -= tmp;
}
for(int i = 1; i < m; i ++) {
int tmp = s - 9 * (m - i - 1);
if(tmp <= 0) {
ans += '0';
}
else {
ans += tmp + '0';
s -= tmp;
}
}
return ans;
} string gMx(int m, int s) {
string ans;
for(int i = 0; i < m; i ++) {
if(s >= 9) {
ans += '9';
s -= 9;
}
else {
ans += s + '0';
s = 0;
}
}
return ans;
} int main() {
int m, s;
while(cin >> m >> s) {
if(s > 9 * m || (m != 1 && s == 0)) {
puts("-1 -1");
continue;
}
if(m == 1 && s == 0) {
puts("0 0");
continue;
}
string Mi = gMi(m, s);
string Mx = gMx(m, s);
cout << Mi << " " << Mx << endl;
}
}
D题:读题花了好久,题目意思就是找菱形(4个点构成)。思路就是dfs2层,对于最后一层假设x点的入度为y。则x点构成的菱形个数为y * (y - 1) / 2
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <memory.h>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring> using namespace std; #define Clear(f, nr) memset(f, nr, sizeof(f))
const int SIZE = 3030;
const int MSIZE = 10000;
const int INF = 1 << 30;
typedef long long ll; vector<int> path[SIZE];
ll ans;
int in[SIZE]; void dfs(int x, int root, int flag) {
if(flag == 0) {
if(x != root)
in[x] ++ ;
return ;
}
for(int i = 0; i < path[x].size(); i ++) {
int son = path[x][i];
dfs(son, root, flag - 1);
}
return ;
} int main() {
int n, m;
int x, y;
while(cin >> n >> m) {
for(int i = 0; i < n; i ++)
path[i].clear();
for(int i = 0; i < m; i ++) {
cin >> x >> y;
x --,y --;
path[x].push_back(y);
}
ans = 0;
for(int i = 0; i < n; i ++) {
Clear(in, 0);
dfs(i, i, 2);
for(int j = 0; j < n; j ++) {
//printf("i:%d, j:%d -> %d\n", i, j, in[j]);
if(in[j] >= 2)
ans += in[j] * (in[j] - 1) / 2;
}
}
cout << ans << endl;
}
}
E题:没读
F题:看了别人的报告。
思路就是:记录每列1的个数。令nr0代表有多少列含有0个1,nr1代表有多少列含1个1。由于和位置无关。递推方程式:
for i,j:
[i][j] += [i-2][j+2] * C(i,2)
[i][j] += [i-1][j-1+1] * C(i,1)*C(j,1)
[i][j] += [i][j-2] * C(j,2)
最后输出f[0][0],代表所有填充完成
由于递推方程式不太好在循环中实现,就改为记忆化搜索,代码例如以下:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <memory.h>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring> using namespace std; #define Clear(f, nr) memset(f, nr, sizeof(f))
const int SIZE = 502;
const int MSIZE = 10000;
const int INF = 1 << 30;
typedef long long ll; ll rec[SIZE][SIZE];
int n, m, mod, x; ll dp(int nr0, int nr1) {
if(rec[nr0][nr1] != -1)
return rec[nr0][nr1];
if(nr0 == nr1 && nr0 == 0)
return rec[0][0] = 1; ll ans = 0;
if(nr0 >= 2) {
ll tmp = dp(nr0 - 2, nr1 + 2) % mod;
tmp = tmp * ((nr0 * (nr0 - 1)) / 2 % mod) % mod;
ans = (ans + tmp) % mod;
}
if(nr1 >= 2) {
ll tmp = dp(nr0, nr1 - 2) % mod;
tmp = tmp * ((nr1 * (nr1 - 1)) / 2 % mod) % mod;
ans = (ans + tmp) % mod;
}
if(nr1 >= 1 && nr0 >= 1) {
ll tmp = dp(nr0 - 1, nr1);
tmp = tmp * ((nr0 * nr1) % mod) % mod;
ans = (ans + tmp) % mod;
}
return rec[nr0][nr1] = ans;
} int main() {
int col[SIZE];
while(cin >> n >> m >> mod) {
Clear(col, 0);
Clear(rec, -1);
for(int i = 0; i < m; i ++)
for(int j = 0; j < n; j ++) {
scanf("%1d", &x);
col[j] += x;
}
int nr0 = 0, nr1 = 0;
for(int j = 0; j < n; j ++) {
if(col[j] == 0) nr0 ++;
else if(col[j] == 1) nr1 ++;
}
cout << dp(nr0, nr1) << endl;
}
}
Codeforces Round #277.5 解题报告的更多相关文章
- Codeforces Round 665 赛后解题报告(暂A-D)
Codeforces Round 665 赛后解题报告 A. Distance and Axis 我们设 \(B\) 点 坐标为 \(x(x\leq n)\).由题意我们知道 \[\mid(n-x)- ...
- Codeforces Round 662 赛后解题报告(A-E2)
Codeforces Round 662 赛后解题报告 梦幻开局到1400+的悲惨故事 A. Rainbow Dash, Fluttershy and Chess Coloring 这个题很简单,我们 ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- Codeforces Round #299 Div2 解题报告
这场比赛并没有打现场,昨天晚上做了ABCD四道题,今天做掉了E题 以前还没有过切完一场比赛的所有题呢~爽~ A. Tavas and Nafas Today Tavas got his test ...
- Codeforces Educational Round 92 赛后解题报告(A-G)
Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...
- Codeforces Round #277 (Div. 2) 题解
Codeforces Round #277 (Div. 2) A. Calculating Function time limit per test 1 second memory limit per ...
- 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation
题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...
- 【codeforces】Codeforces Round #277 (Div. 2) 解读
门户:Codeforces Round #277 (Div. 2) 486A. Calculating Function 裸公式= = #include <cstdio> #include ...
- Codeforces Round #277 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/486 A题.Calculating Function 奇偶性判断,简单推导公式. #include<cstdio> ...
随机推荐
- hbase启动报错:Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
输入HBASE_MASTER_OPTS只是为了快速寻找这个选项而已,如果你手工找也可以 刚才那个命令回车后直接跳到这 前面加#就好了 修改后保存.重新启动hbase就好了. 注意:各个节点都要修改哦. ...
- ToF相机学习笔记之基本知识
ToF相机属于一种非接触式光学传感器,通过计算发射激光的飞行时间获取对应像素的深度信息.就非接触式距离测量方法而言,其分类可用下表表示如下: 1.1 ToF传感器基础 一个逐点式的ToF传感器采用了雷 ...
- AIX 系统补丁升级步骤
AIX 系统补丁升级步骤 1.升级之前建议备份 rootvg (推荐) # smit mksysb 2.检查系统版本号 # oslevel -r 3.找到补丁光盘或者下载补丁,上传到服务器 ...
- 手动脱FSG壳实战
作者:Fly2015 对于FSG壳.之前没有接触过是第一次接触.这次拿来脱壳的程序仍然是吾爱破解论坛破解培训的作业3的程序.对于这个壳折腾了一会儿,后来还是被搞定了. 1.查壳 首先对该程序(吾爱破解 ...
- Android Studio升级到0.8.1后怎样设置字体大小?
升级到0.8.1后.打开设置字体大小页面.你会发现无论是Default还是Darcula,都不同意你改变字体的大小.事实上这个是由于这两个模式是Android Studio自带模式,所以不同意你修改, ...
- HBase 数据库检索性能优化策略
HBase 数据表介绍 HBase 数据库是一个基于分布式的.面向列的.主要用于非结构化数据存储用途的开源数据库.其设计思路来源于 Google 的非开源数据库"BigTable" ...
- CF 246 div2 D Prefixes and Suffixes (全部前缀的出现次数)
题目链接:http://codeforces.com/contest/432/problem/D 题意:对一个长度不超过10^5的字符串.按长度输出和后缀全然匹配的的前缀的长度,及该前缀在整个串中出现 ...
- MAC 下的简单 SHELL 入门
1.创建文件 .sh 文件 本例,将 sh 文件全名为 demo.sh,接下来使用随意熟悉的编辑器编辑命令就可以 2.编写 .sh 文件 #!/bin/sh echo +--------------- ...
- 48.Cookie 管理
转自:http://www.runoob.com/nodejs/nodejs-express-framework.html 我们可以使用中间件向 Node.js 服务器发送 cookie 信息,以下代 ...
- js --- 事件流
1.事件流 事件发生时会在元素节点与根节点之间按照特定的顺序传播,路径所经过的所有节点都会收到该事件,这个传播过程即DOM事件流. 2.两种事件流模型 1.冒泡型事件流:事件的传播是从最特定的事件目标 ...