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 ...
随机推荐
- 【Linux】Linux学习笔记(完结)
前言 在工作中发现Linux系统的重要性,于是计划重温下Linux,顺便记录笔记方便之后查阅. 磁盘分区 在Linux系统中,每个设备都被当成一个文件来对待:如IDE接口的硬盘文件名为/dev/hd[ ...
- ArcGIS API for JavaScript 4.2学习笔记[19] 搜索小部件——使用更多数据源
上一篇中提到,空间搜索小部件是Search这个类的实例化,作为视图的ui属性添加进去后,视图就会出现搜索框了. 这节的主体代码和上篇几乎一致,区别就在上篇提及的sources属性. 先看看结果: 由于 ...
- centOS7 jdk安装
1.查找需要卸载的OpenJDK: # rpm -qa | grep java 2:依次卸载 rpm -e --nodeps javapackages-tools-3.4.1-6.el7_0.noa ...
- Python:监控ASM剩余空间
#!/usr/bin/env python # -*- coding:utf-8 -*- __author__ = 'Jipu FANG' version = 0.1 import cx_Oracle ...
- 让 kibana 后台启动的方案
为了解决启动kibana后关闭shell终端kibana自动关闭的问题,记录2种解决方案,试验后均可行. 假设kibana安装的目录为 /usr/local/kibana/ 方案一: 使用nohup ...
- webpack配置报错:invalid configuration object.webpack has been initialisted using a configuration objcet that does not match thie API schema
最近接收了别人的项目,webpack配置总是报错如下:最后找到了解决办法,在此分享一下: 错误情况: 解决办法: 将package.json里面的colors删除掉即可
- 服务器 Python服务停服、起服脚本
近日,在阿里云服务器上部署了一个Python,Web框架为Tornado,服务器为Ubuntu 16.04. 服务的启动也十分的简单: python services.py 我是利用Xshell工具连 ...
- CSS 去掉inline-block间隙的几种方法
最近做移动端页面时,经常会用到inline-block元素来布局,但无可避免都会遇到一个问题,就是inline-block元素之间的间隙.这些间隙会导致一些布局上的问题,需要把间隙去掉.对于inlin ...
- 使用Word进行文档修订版本的比较
项目经理在实际的工作过程中,比如要写文档方案,就需要对文档的修订版本进行管理和控制.在以前的工作中,笔者使用的是UltraEdit这个软件工具中的Ultra Compare这个子工具来进行的文档版本的 ...
- Linux入门篇(二)——文件
这一系列的Linux入门都是本人在<鸟哥的Linux私房菜>的基础上总结的基本内容,主要是记录下自己的学习过程,也方便大家简要的了解 Linux Distribution是Ubuntu而不 ...