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

  1. Codeforce - Street Lamps

    Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...

  2. Codeforce Round #216 Div2

    e,还是写一下这次的codeforce吧...庆祝这个月的开始,看自己有能,b到什么样! cf的第二题,脑抽的交了错两次后过了pretest然后system的挂了..脑子里还有自己要挂的感觉,果然回头 ...

  3. Codeforce 水题报告(2)

    又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数( ...

  4. codeforce 367dev2_c dp

    codeforce 367dev2_c dp 标签: dp 题意: 你可以通过反转任意字符串,使得所给的所有字符串排列顺序为字典序,每次反转都有一定的代价,问你最小的代价 题解:水水的dp...仔细想 ...

  5. 三维dp&codeforce 369_2_C

    三维dp&codeforce 369_2_C 标签: dp codeforce 369_2_C 题意: 一排树,初始的时候有的有颜色,有的没有颜色,现在给没有颜色的树染色,给出n课树,用m种燃 ...

  6. 强连通分量&hdu_1269&Codeforce 369D

    强连通分量 标签: 图论 算法介绍 还记得割点割边算法吗.回顾一下,tarjan算法,dfs过程中记录当前点的时间戳,并通过它的子节点的low值更新它的low,low值是这个点不通过它的父亲节点最远可 ...

  7. 【树状数组】区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D

    [树状数组]区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D PROBLEM 题目描述 初始给定n个卡片拍成一排,其中第i个卡片上的数为x[i]. 有q个询问,每次询问 ...

  8. 解题报告:codeforce 7C Line

    codeforce 7C C. Line time limit per test1 second memory limit per test256 megabytes A line on the pl ...

  9. Two progressions CodeForce 125D 思维题

    An arithmetic progression is such a non-empty sequence of numbers where the difference between any t ...

随机推荐

  1. hibernate核心API使用

    1.Configuration 加载核心配置文件,核心配置文件名称和位置固定,否则会找不到 2.SessionFactory对象一个项目只创建一个,大家公用 根据配置文件和映射关系创建表 由于要创建表 ...

  2. 入门级Nginx反向代理nodejs

    本着想实现前后端分离开发的初衷,我决定学习一下关于nignx反向代理的配置. 1.下载Nginx稳定版本 2.打开nginx配置文件 nginx.conf: 3.在http模块的server部分配置 ...

  3. lesson - 6 课程笔记

    一.df  作用:  显示磁盘分区上的可使用的磁盘空间, 默认显示单位为kb . 可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间的等信息. 选项: -a :包含全部的文件系统 -h :以 ...

  4. mkdir 命令详解

    rmdir  <man.linuxde.net> 作用: rmdir 命令用来创建目录,该命令创建由dirname 命名的目录.如果在目录名的前面没有添加任何路径名,则在当前目录下创建由d ...

  5. 跟我一起学JQuery插件开发教程

    在逛codeproject网站的时候,突然看到一篇文章:How to write plugin in Jquery. 如果对E文好的同学 ,可以看上面的连接.现在我把上面网站的及结合自己的想法写这篇文 ...

  6. 例子:js超级玛丽小游戏

    韩顺平_轻松搞定网页设计(html+css+javascript)_第34讲_js超级玛丽小游戏_学习笔记_源代码图解_PPT文档整理 采用面向对象思想设计超级马里奥游戏人物(示意图) 怎么用通过按键 ...

  7. Asp.net IIS Express 无法启动 解决办法

    http://www.mamicode.com/info-detail-1893424.html 一 .其他项目都可以,就这么一个不行 用记事本或者其他什么文本编辑器,打开项目的.csproj文件,定 ...

  8. Django中Q查询及Q()对象

    问题 一般我们在Django程序中查询数据库操作都是在QuerySet里进行进行,例如下面代码: >>> q1 = Entry.objects.filter(headline__st ...

  9. Fiddler的hosts配置使用

    前提:使用fiddler的hosts配置,可以方便的配置自己想要测试环境,不需要每次配置hosts都到windows目录下去修改hosts文件 1.点击Tool->HOSTS,打开hosts的配 ...

  10. golang 数组反转

    我做hackerearth上题目记录,具体的题目描述是这样的: Given the size and the elements of array A, print all the elements i ...