codeforce 375_2_b_c
codeforce 375_2
标签: 水题
好久没有打代码,竟然一场比赛两次卡在边界条件上。。。。跪
b.题意很简单。。。纯模拟就可以了,开始忘记了当字符串结束的时候也要更新两个值,所以就错了
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 300;
char a[N];
int main()
{
int n;
int l;
int sum;
int tm;
int Max;
while(~scanf("%d",&n))
{
getchar();
gets(a);
a[n] = '_';
l = tm = sum = Max = 0;
for(int i = 0; i <= n; i++)
{
if(a[i]!='('&&a[i]!=')'&&a[i]!='_'){
tm++;
}
else if(a[i]=='(') {
if(l==0&&tm>0) Max = max(Max,tm);
if(l>0&&tm>0) sum++;
l++;
tm = 0;
}
else if(a[i]==')'){
l--;
if(tm>0) sum++;
tm = 0;
}
else if(a[i]=='_'){
if(l==0){
if(tm>0) Max = max(Max,tm);
}
else if(l>0){
if(tm>0) sum++;
}
tm = 0;
}
}
printf("%d %d\n",Max,sum);
}
return 0;
}
c.题意:一个巧妙的写法,已知最后每个数字最后应该出现的位置个数是\([n/m]\)那么我们可以从前到后扫描一遍,遇到非法的位置,将这个位置换成一个需要被替换的值(要先处理好每个数已经有了几个,换成个数不够的数字就好了)但是。。。我又脑残的忘记了top要限制<m不然有可能越界。。。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 2010;
struct Node{
int num;
int all;
bool operator <(const Node n) const
{
return all<n.all;
}
}cnt[N];
int mp[N];
int vis[N];
int jd[N];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
int tm = n/m;
int c = 0;
for(int i = 1; i <= m; i++) cnt[i].num = i,cnt[i].all = 0;
for(int i = 0; i < n; i++){
scanf("%d",&mp[i]);
if(mp[i]<=m){
cnt[mp[i]].all++;
}
}
int sum = 0;
for(int i = 1; i <= m; i++){
if(cnt[i].all<tm) sum+=(tm-cnt[i].all);
}
sort(cnt+1,cnt+m+1);
int top = 1;
memset(vis,0,sizeof(vis));
for(int i = 0; i < n; i++){
if(mp[i]<=m&&vis[mp[i]]<tm) {
vis[mp[i]]++;
}
else {
if(cnt[top].all >= tm) {
top++;
if(cnt[top].all>=tm) break;
}
mp[i] = cnt[top].num;
cnt[top].all++;
vis[mp[i]]++;
}
}
printf("%d %d\n",tm,sum);
for(int i = 0; i < n-1; i++){
printf("%d ",mp[i]);
}
printf("%d\n",mp[n-1]);
}
}
codeforce 375_2_b_c的更多相关文章
- Codeforce - Street Lamps
Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...
- Codeforce Round #216 Div2
e,还是写一下这次的codeforce吧...庆祝这个月的开始,看自己有能,b到什么样! cf的第二题,脑抽的交了错两次后过了pretest然后system的挂了..脑子里还有自己要挂的感觉,果然回头 ...
- Codeforce 水题报告(2)
又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数( ...
- codeforce 367dev2_c dp
codeforce 367dev2_c dp 标签: dp 题意: 你可以通过反转任意字符串,使得所给的所有字符串排列顺序为字典序,每次反转都有一定的代价,问你最小的代价 题解:水水的dp...仔细想 ...
- 三维dp&codeforce 369_2_C
三维dp&codeforce 369_2_C 标签: dp codeforce 369_2_C 题意: 一排树,初始的时候有的有颜色,有的没有颜色,现在给没有颜色的树染色,给出n课树,用m种燃 ...
- 强连通分量&hdu_1269&Codeforce 369D
强连通分量 标签: 图论 算法介绍 还记得割点割边算法吗.回顾一下,tarjan算法,dfs过程中记录当前点的时间戳,并通过它的子节点的low值更新它的low,low值是这个点不通过它的父亲节点最远可 ...
- 【树状数组】区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D
[树状数组]区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D PROBLEM 题目描述 初始给定n个卡片拍成一排,其中第i个卡片上的数为x[i]. 有q个询问,每次询问 ...
- 解题报告:codeforce 7C Line
codeforce 7C C. Line time limit per test1 second memory limit per test256 megabytes A line on the pl ...
- Two progressions CodeForce 125D 思维题
An arithmetic progression is such a non-empty sequence of numbers where the difference between any t ...
随机推荐
- mysql5.7-Group Replication
什么是Group Replication 基于组的复制(Group-based Replication)是一种被使用在容错系统中的技术.Replication-group(复制组)是由能够相互通信的多 ...
- bzoj 1758: [Wc2010]重建计划
Description Input 第 一行包含一个正整数N,表示X国的城市个数. 第二行包含两个正整数L和U,表示政策要求的第一期重建方案中修建道路数的上下限 接下来的N-1行描述重建小组的原有方案 ...
- bzoj 4199: [Noi2015]品酒大会
Description 一年一度的"幻影阁夏日品酒大会"隆重开幕了.大会包含品尝和趣味挑战两个环节,分别向优胜者颁发"首席品酒家"和"首席猎手&quo ...
- 安装lamp代码
tar -zxvf mysqladdUser mysql -s /sbin/nologinmv mysql /usr/local/mysql (改目录下直接存储bin docs等目录)mkdir -p ...
- ActiveMQ (二) 常用配置简介
ActiveMQ的主要配置文件 ActiveMQ的一些常用的属性很多可以在对应的配置文件中进行配置的.比如访问web console的管理端的端口,用户名密码,连接MQ时的用户名和密码,持久化设置,是 ...
- Design Patterns笔记
一些笔记. strategy : facilitates the switch of the different but related algorithms/behaviors observer p ...
- css3整理-方便查询使用
最近详细地研究了CSS3的相关内容,并整理了这个文档,方便以后查询使用,分享给大家. 案例代码大家可以下载参考下:https://gitee.com/LIULIULIU8/CSS3 1.边框属性bor ...
- 给yii架构的网站做Android客户端
网站未预留接口.给这类网站制作客户端就是模拟网页发送的post和get请求,然后获取服务器返回的数据. 1.在做客户端时先使用httpwatch分析浏览器发送的get和post请求的内容和URL.分析 ...
- 不解释,分享这个base.css
@charset "utf-8"; /*! * @名称:base.css * @功能:1.重设浏览器默认样式 * 2.设置通用原子类 */ /* 防止用户自定义背景颜色对网页的影响 ...
- Java核心技术(Java白皮书)卷Ⅰ 第一章 Java程序设计概述
第1章 Java程序设计概述1.1 Java程序设计平台 具有令人赏心悦目的语法和易于理解的语言,与其他许多优秀语言一样,Java满足这些要求. 可移植性 垃圾收集 提供大型的库 如果想要有奇特的绘 ...