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 ...
随机推荐
- Android LayoutInflator 解析
一.实际使用场景引入: 在ListView的Adapter的getView方法中基本都会出现,使用inflate方法去加载一个布局,用于ListView的每个Item的布局. 同样,在使用ViewP ...
- Linux_异常_08_本机无法访问虚拟机web等工程
这是因为防火墙的原因,把响应端口开启就行了. # Firewall configuration written by system-config-firewall # Manual customiz ...
- inux_异常_07_ftp查看不到文件列表
二.参考资料 1.Linux关于ftp查看不到文件列表的问题
- SVN添加用户权限
点击properties
- \Process(sqlservr)\% Processor Time 计数器飙高
计数器" \Process(sqlservr)\% Processor Time",是经常监测,看看SQL Server如何消耗CPU资源.sqlserver是如何利用现有的资源; ...
- BASIC-2 01字串
基础练习 01字串 时间限制:1.0s 内存限制:256.0MB 问题描述 对于长度为5位的一个01串,每一位都可能是0或1,一共有32种可能.它们的前几个是: 00000 ...
- Spark算子篇 --Spark算子之aggregateByKey详解
一.基本介绍 rdd.aggregateByKey(3, seqFunc, combFunc) 其中第一个函数是初始值 3代表每次分完组之后的每个组的初始值. seqFunc代表combine的聚合逻 ...
- iOS 动画篇 之 Core Animation (一)
iOS中实现动画有两种方式,一种是自己不断的通过drawRect:方法来绘制,另外一种就是使用核心动画(Core Animation). 导语: 核心动画提供高帧速率和流畅的动画,而不会增加CPU的负 ...
- shader程序员需要注意的优化Tips
在写shader的时候,其实一些写法对于其执行影响非常大,而且由于gpu和cpu在架构上的不同,代码的优化思想也不一样,最近一直在写几个shader,为了性能问题,查阅了很多资料,把一些tips总结下 ...
- 关于new Date()
1. 将时间戳转换成日期格式 // 简单的一句代码 var date = new Date(时间戳); //获取一个时间对象 /** 1. 下面是获取时间日期的方法,需要什么样的格式自己拼接起来就好了 ...