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)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. UIBezierPath的使用方法

    UIBezierPath的使用方式: 一,直接添加轨迹,然后stroke或者fill UIColor *blue =[UIColor blueColor]; [blue set]; UIBezierP ...

  2. springboot jpa 多条件查询(单表)

    需要实现的功能: 多个搜索输入框:全部不填,则查出所有列表:填了条件,就按条件查找:填的条件个数不定. 方法实现的核心:jpa自带的Specification<T> (目前只需要单表,多表 ...

  3. [转] Entity Framework添加记录时获取自增ID值

    本文转自:http://blog.csdn.net/educast/article/details/8632806 与Entity Framework相伴的日子痛并快乐着.今天和大家分享一下一个快乐, ...

  4. SQL 工具系列二

    1.RedGate 工具 SQL Prompt 脚步智能提示工具 脚步提示工具,轻松写入,编辑和探索SQL: SQL Prompt能根据数据库的对象名称,语法和用户编写的代码片段自动进行检索,智能的为 ...

  5. 在Android下通过ExifInterface类操作图片的Exif信息

    什么是Exif 先来了解什么是Exif.Exif是一种图像文件格式,它的数据存储于JPEG格式是完全相同的,实际上Exif格式就是JPEG格式头插入了 数码照片的信息,包括拍摄的光圈.快门.平衡白.I ...

  6. Layer UI 模块化的用法(转)

    此文章适合入门的同学查看,之前因为项目的原因,在网上找了一套Layer UI做的后台管理系统模板,完全不懂LayUI里面的JS用法,看了官方文档和其它资料后才明白怎么去实现模块化这个例子,但是还是感觉 ...

  7. NodeJs接口token认证express框架passport实现方式Bearer认证

    1.生成一个简单的express项目(命令:express passport-test),项目结构如下: 2.添加项目依赖: npm install passport --save npm insta ...

  8. RabbitMQ基础--总结

    一. RabbitMQ的五种工作场景: 1. 单发单收 2. 单发送多接收 +++++++++++++++++++++前面两种没有使用exchange++++++++++++++++++ 3. Pub ...

  9. ES5 object方法整理

    Object.getPrototypeOf(object):调用对象父类原型上的方法; function Person(){ this.method1 = function(){alert(1)} } ...

  10. eclipse Java类 红色感叹号 commit失败

    解决方法:  1.进入java类文件所在物理目录 (e:\workspace\myproject\...) 2. 删除多余的版本管理工具的文件或文件夹(如 .svn) 3. 刷新eclipse工程 4 ...