题意:

输入一系列的数,连续数字则输出连续区间

看第一个案例就很明显

思路:

输入字符串输入,预处理一下。

写了个挫尺取…

贴一发挫code…….

#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
typedef long long LL; int a[102];
int b[5];
char s[500];
bool vis[1010]; int main()
{
while(~scanf("%s",s))
{
int x;
int len=strlen(s);
bool flag=false;
memset(vis,0,sizeof(vis));
x=0;
for(int i=0;i<len;i++)
{
if(s[i]==',')
{
int bb=0;
if(x)
{
for(int j=1;j<=x;j++)
{
bb=bb*10+b[j];
}
}
if(!vis[bb])
{
vis[bb]=1;
}
x=0;
flag=0;
}
else
{
b[++x]=s[i]-'0';
flag=1;
}
}
if(flag)
{
int bb=0;
if(x)
{
for(int j=1;j<=x;j++)
{
bb=bb*10+b[j];
}
}
if(!vis[bb])
vis[bb]=1;
}
int s,t;
flag=false;
for(s=1;s<1000;s++)
{
while(!vis[s]&&s<=1000)
s++;
t=s;
if(s>1000)
{
if(vis[1000])
{
if(flag) printf(",");
printf("1000");
}
break;
}
while(vis[t]&&t<=1000)
t++;
t--; if(s==t)
{
if(flag) printf(",");
printf("%d",s);
flag=1;
}
else
{
if(flag) printf(",");
printf("%d-%d",s,t);
flag=1;
}
s=t;
//printf("%d %d\n",s,t);
}
puts("");
}
return 0;
}

Codeforces34C【尺取】的更多相关文章

  1. Gym 100703I---Endeavor for perfection(尺取)

    题目链接 http://codeforces.com/problemset/gymProblem/100703/I Description standard input/outputStatement ...

  2. NOJ 1072 The longest same color grid(尺取)

    Problem 1072: The longest same color grid Time Limits:  1000 MS   Memory Limits:  65536 KB 64-bit in ...

  3. hdu 4123 Bob’s Race 树的直径+rmq+尺取

    Bob’s Race Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Probl ...

  4. Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)

    题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...

  5. poj2566尺取变形

    Signals of most probably extra-terrestrial origin have been received and digitalized by The Aeronaut ...

  6. poj2100还是尺取

    King George has recently decided that he would like to have a new design for the royal graveyard. Th ...

  7. hdu 6231 -- K-th Number(二分+尺取)

    题目链接 Problem Description Alice are given an array A[1..N] with N numbers. Now Alice want to build an ...

  8. Codeforces 939E Maximize! (三分 || 尺取)

    <题目链接> 题目大意:给定一段序列,每次进行两次操作,输入1 x代表插入x元素(x元素一定大于等于之前的所有元素),或者输入2,表示输出这个序列的任意子集$s$,使得$max(s)-me ...

  9. cf1121d 尺取

    尺取,写起来有点麻烦 枚举左端点,然后找到右端点,,使得区间[l,r]里各种颜色花朵的数量满足b数组中各种花朵的数量,然后再judge区间[l,r]截取出后能否可以供剩下的n-1个人做花环 /* 给定 ...

随机推荐

  1. poj1870--Bee Breeding(模拟)

    题目链接:点击打开链接 题目大意:给出一个蜂窝,也就是有六边形组成,从内向外不断的循环(如图).给出两个数的值u,v按六边形的走法,由中心向六个角走.问由u到v的的最小步数. 首先处理处每个数的坐标, ...

  2. uva 11488 - Hyper Prefix Sets(字典树)

    H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...

  3. C# json反序列化 对象中嵌套数组 (转载) 可能会导致循环或多重级联路径。请指定 ON DELETE NO ACTION 或 ON UPDATE NO ACTION,或修改其他 FOREIGN KEY 约束。

    C# json反序列化 对象中嵌套数组 (转载)   看图: 这里可以看到是二层嵌套!!使用C#如何实现?? 思路:使用list集合实现 → 建立类 → list集合 → 微软的   Newtonso ...

  4. Intel processor brand names-Xeon,Core,Pentium,Celeron----Celeron

    http://en.wikipedia.org/wiki/Celeron Celeron From Wikipedia, the free encyclopedia     Celeron Produ ...

  5. 基于mac系统的apacheserver的使用流程

    打开终端.输入下面命令:sudo apachectl start 此时Apache已经开启.在浏览器中输入本地ip地址能够看到it works! 打开前往----电脑------Macintosh H ...

  6. SELECT INSTR(120,0000); 真

    sql 排故 SELECT  INSTR(120,0000);  真

  7. SHOW PROCESSLIST Syntax

    https://dev.mysql.com/doc/refman/5.7/en/show-processlist.html SHOW PROCESSLIST shows you which threa ...

  8. GSON的简单示例

    https://github.com/google/gson package com.example.wolf; import com.google.gson.JsonArray; import co ...

  9. ruby hash排序

    参考文章:http://blog.csdn.net/ppp8300885/article/details/49933305 a={a:1,b:20,c:3,d:0,e:7}逆序 a.sort{|k,v ...

  10. 附录: mysql show processlist中的State的意义

    附录: mysql show processlist中的State的意义 Checking table 正在检查数据表(这是自动的). Closing tables 正在将表中修改的数据刷新到磁盘中, ...