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. iOS框架搭建(MVC,自定义TabBar)--微博搭建为例

    项目搭建 1.新建一个微博的项目,去掉屏幕旋转 2.设置屏幕方向-->只有竖向 3.使用代码构建UI,不使用storyboard 4.配置图标AppIcon和LaunchImage 将微博资料的 ...

  2. MySQL时间操作的系统函数用法

    我要查询获得当天凌晨30分的datetime值的方式:select ADDDATE(CURDATE(), INTERVAL TIME_TO_SEC(TIMEDIFF("00:30:00&qu ...

  3. xcode编译报错unknown error -1=ffffffffffffffff Command /bin/sh failed with exit code 1

    升级完xcode9.1之后,编译项目出现如下错误: CI今日构建时报出如下错误: /Users/xxx/Library/Developer/Xcode/DerivedData/Snowball-ebl ...

  4. 初学者福音——10个最佳APP开发入门在线学习网站

    根据Payscale的调查显示,现在的APP开发人员的年薪达到:$66,851.这也是为什么那么多初学的开发都想跻身到APP开发这行业的主要原因之一.每当你打开App Store时候,看着琳琅满目的A ...

  5. Maven打包排除某个资源或者目录

    最近在spark streaming本地调试的时候,引入了一些资源文件,打包的时候需要给排除掉.所以就考虑使用maven的方式 详细参考官方文档:https://maven.apache.org/pl ...

  6. CSS3 自定义动画(animation)

    除了在之前的文章中介绍过的 CSS3 的变形 (transformation) 和转换 (transition) 外,CSS3 还有一种自由度更大的自定义动画,开发者甚至可以使用变形(transfor ...

  7. java多线程(四)-自定义线程池

    当我们使用 线程池的时候,可以使用 newCachedThreadPool()或者 newFixedThreadPool(int)等方法,其实我们深入到这些方法里面,就可以看到它们的是实现方式是这样的 ...

  8. SQLServer 索引总结

    测试案例: SET STATISTICS IO ON SET STATISTICS TIME ON SET STATISTICS PROFILE ON SELECT  count(A.CarrierT ...

  9. css中的 nav ul li ul 与 nav>ul>li 这两种写法的区别

    <nav> <ul id="a"> <li>a1</li> <li>a2</li> <li>a3 ...

  10. MicroPython可视化编程开发板—TurnipBit自制MP3教程实例

    转载请以链接形式注明文章来源(MicroPythonQQ技术交流群:157816561,公众号:MicroPython玩家汇) 当前我们都生活在一个有声有色的社会当中,欣赏美丽的景色,享受动人的音乐, ...