Codeforces Round #423 (Div. 2)
codeforces 423 A. Restaurant Tables 【水题】
//注意,一个人选座位的顺序,先去单人桌,没有则去空的双人桌,再没有则去有一个人坐着的双人桌。读清题意。
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n, a, b, bb, x;
int main()
{
int ans = ;
scanf("%d%d%d", &n, &a, &b);
while(n--) {
scanf("%d", &x);
if(x==) {
if(a) a--;
else if(b) b--, bb++;
else if(bb) bb--;
else ans++;
}
else {
if(b) b--;
else ans += ;
}
}
printf("%d\n", ans);
return ;
}
codeforces 423 B. Black Square 【模拟】
题意:求需要将几块W涂成B能使所有B组成方形
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = ;
char s[N][N];
int n, m, ans;
int main()
{
int i, j, cnt = ;
scanf("%d%d", &n, &m);
int l1=m-, l2=n-, r1=, r2=;
for(i = ; i < n; ++i) scanf("%s", s[i]);
for(i = ; i < n; ++i) {
for(j = ; j < m; ++j) {
if(s[i][j] == 'B') {
cnt++;
l1 = min(l1, j); l2 = min(l2, i);
r1 = max(r1, j); r2 = max(r2, i);
}
}
}
int len = max(r1-l1+, r2-l2+);
if(len > min(n, m)) ans = -;
else if(!cnt) ans = ;
else { ans = len*len - cnt; }
printf("%d\n", ans);
return ;
}
codeforces 423 C. String Reconstruction 【字符串】
题意:给你n个子串的出现次数和出现位置,构造原字符串,要求字典序最小。
//对每个子串出现位置判断有没有和前一个位置的区间重复,从没有重复的部分继续构造,避免超时。
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 2e6+;
char s[N], t[N];
int n, k, x, ans;
int main()
{
memset(s, 'a', sizeof(s));
int i, j, r = ;
scanf("%d", &n);
while(n--) {
scanf("%s %d", t, &k);
int len = strlen(t);
int pre = -len;
for(i = ; i < k; ++i) {
scanf("%d", &x);
for(j = max(, len-(x-pre)); j < len; ++j)
s[j+x-] = t[j];
pre = x;
r = max(r, x+len-);
}
}
for(i = ; i < r; ++i)
printf("%c", s[i]);
puts("");
return ;
}
codeforces 423 D. High Load 【构造】
题意:给出结点总数n和出口结点数k,(出口结点度数为1,其他结点度数至少为2, 结点编号为1~n)构造网络,使得两个最远的出口节点之间的距离最小的。(两节点之间的距离是这两个节点之间的线数)。输出最远结点之间的最小距离 和 构造出的网络。
题解:就是构造一棵深度最小的树,先将k个结点都与根结点相连,然后依次将剩余结点与这k个结点相连,层次性加深树的深度即可。
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n, k, m, h, d;
int main()
{
int i, ans;
scanf("%d%d", &n, &k);
h = (n-) / k;
d = (n-) % k;
if(!d) ans = * h;
else if(d == ) ans = * h + ;
else ans = * h + ;
printf("%d\n", ans);
for(i = ; i <= k+; ++i) printf("1 %d\n", i);
for(i = k+; i <= n; ++i) printf("%d %d\n", i, i-k);
return ;
}
Codeforces Round #423 (Div. 2)的更多相关文章
- Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals)
Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals) A.String Reconstruction B. High Load C ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) E. DNA Evolution 树状数组
E. DNA Evolution 题目连接: http://codeforces.com/contest/828/problem/E Description Everyone knows that D ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) D. High Load 构造
D. High Load 题目连接: http://codeforces.com/contest/828/problem/D Description Arkady needs your help ag ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) C. String Reconstruction 并查集
C. String Reconstruction 题目连接: http://codeforces.com/contest/828/problem/C Description Ivan had stri ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) A,B,C
A.题目链接:http://codeforces.com/contest/828/problem/A 解题思路: 直接暴力模拟 #include<bits/stdc++.h> using ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem E (Codeforces 828E) - 分块
Everyone knows that DNA strands consist of nucleotides. There are four types of nucleotides: "A ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 828D) - 贪心
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 828C) - 链表 - 并查集
Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem A - B
Pronlem A In a small restaurant there are a tables for one person and b tables for two persons. It i ...
随机推荐
- poj 1284 Primitive Roots(未完)
Primitive Roots Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3155 Accepted: 1817 D ...
- B/S结构中页面间的传值
常见的页面间的传值有session,cookie,application,server.transfer(),queryString,今天主要记录一下server.transfer()的用法. 从A页 ...
- 自动收缩数据库T-SQL
alter database 数据库名 set auto_update_statistics off alter database 数据库名 set auto_update_statistics on
- 远程桌面下启动MATLAB时的License Manager Error -103错误
之前使用学校提供的正版lincense,是通过MATLAB 官网注册下载的MATLAB 2017a,远程登录可用打开.后来学校停止购买了,时间紧迫,网上下载了一个standalone的lincense ...
- 项目开发-->基础功能汇总
祭奠曾经逝去的青春…… 1.基础功能汇总-->身份认证及用户登录模块 2.基础功能汇总-->一键登录功能汇总 3.堆和栈 4.变量
- package和package-lock区别;dependencies和devDependencies区别
package和package-lock package.json: 主要用来定义项目中需要依赖的包 package-lock.json: 在 npm install时候生成一份文件,用以记录当前状态 ...
- 原生JS编写getByClass、addClass、removeClass、hasClass
前言: 年后换了工作,在现在的公司写交互主要使用JS原生:刚刚入门前端的时候写交互一直用的原生JS,虽然用的不怎么样.后来去之前的公司之后,leader主张把jQuery用好,JS原生自然就熟练了:一 ...
- 初识 ElasticSearch
场景:最近有同事分享了ElasticSearch Inverted Index,所以自己也了解一下基于Lucene的ES. 转载自:http://www.jianshu.com/p/05cff7175 ...
- Perl学习笔记(2)----正则表达式数字匹配的一个疏忽
<Perl语言入门>第15章习题第2题如下: 用 given-when 结构写一个程序,根据输入的数字,如果它能被3整除,就打印“Fizz”:如果它能被5整除,就打印“Bin”:如果它能被 ...
- HBuilder自定义格式化代码
对于代码格式到底为两个空格还是四个空格,可能大家喜欢的都不同,如果你是在使用HBuilder编辑器,那么恭喜你,这两种代码格式你可以轻易的更换.下面贴步骤 1.打开工具—>选项 2.选择HBui ...