hdu 1199 Color the Ball
http://acm.hdu.edu.cn/showproblem.php?pid=1199
Color the Ball
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5135 Accepted Submission(s): 1262
There are multiple cases, process to the end of file.
1 4 w
8 11 w
3 5 b
开始看到这道题以为要用到线段树会很难,仔细一想发现并不是多难,用一般方法就可以解决正常模拟一下染色,
0为黑色1位白色,然后循环统计每一段的白色个数,并将其起点和终点记录到结构体中,
通过排序找到白色个数最多的那一段,输出其起点和终点,即为该题结果
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define N 200010//这里注意开大点 using namespace std; struct st
{
int x, y, ans;//x表示白色部分的起点,y表示终点,ans表示这段区间的白色的数量
} node[N]; int G[N];//G[i] 0表示黑色 1表示白色 int cmp(const void *a, const void *b)
{
st *s1 = (st *)a, *s2 = (st *)b;
if(s1->ans == s2->ans)
return s1->x - s2->x;
else
return s2->ans - s1->ans;
} int main()
{
int n, a, b, i, f, k, j, Max;
char ch;
while(~scanf("%d", &n))
{
f = k = j = Max = ;
memset(G, , sizeof(G));
memset(node, , sizeof(node));
while(n--)
{
scanf("%d%d %c", &a, &b, &ch);
Max = max(max(a, b), Max);
if(ch == 'w')
for(i = a ; i <= b ; i++)
G[i] = ;
else
for(i = a ; i <= b ; i++)
G[i] = ;
}
for(i = ; i < Max ; i++)
{
if(G[i] == )
{
f = ;
break;
}
}
if(f == )
{
printf("Oh, my god\n");
continue;
}
for(i = ; i <= Max ; i++)
{
if(G[i] == )
{
node[j].ans++;
if(k == )
{
node[j].x = i;
k = ;
}
}
if(G[i] == && k == )
{
node[j].y = i - ;
k = ;
j++;
}
if(G[i] == && i == Max && k == )
{
node[j].y = i;
k = ;
j++;
}
}
qsort(node, j, sizeof(node[]), cmp);
printf("%d %d\n", node[].x, node[].y);
}
return ;
} /*
3
1 4 w
8 11 w
3 5 b
4
1 4 w
8 11 w
3 5 b
6 8 w*/
hdu 1199 Color the Ball的更多相关文章
- hdu 1199 Color the Ball(离散化线段树)
Color the Ball Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- hdu 1199 Color the Ball 离散线段树
C - Color the Ball Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- ZOJ 2301 / HDU 1199 Color the Ball 离散化+线段树区间连续最大和
题意:给你n个球排成一行,初始都为黑色,现在给一些操作(L,R,color),给[L,R]区间内的求染上颜色color,'w'为白,'b'为黑.问最后最长的白色区间的起点和终点的位置. 解法:先离散化 ...
- HDU 1199 - Color the Ball 离散化
[题意]现在有几个球排成一排,编号从1开始,开始时所有球为黑色,现在有n(<=2000)次操作,每次操作将l[i]至r[i](均在int范围)的球凃成颜色c[i](黑色'b'或白色'w'),然后 ...
- hdu 1556:Color the ball(第二类树状数组 —— 区间更新,点求和)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1556:Color the ball(线段树,区间更新,经典题)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- HDU 1556 Color the ball (数状数组)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- 线段树(求单结点) hdu 1556 Color the ball
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
随机推荐
- UVa 10905 Children's Game
注意!这不是单纯的字典序排序,比如90.9,应该是990最大 对字符串排序蛋疼了好久,因为别人说string很慢,所以一直没有用过. 看别人用string还是比较方便的,学习一下 对了,这里的cmp函 ...
- 一些纯css3写的公司logo
随着对css3了解得越深入,越来越发现了css3的强大.css3不但能完成一些基本的特效如圆角阴影等,还能借助动画技术实现一些复杂的动画,能替代很多以前js才能完成的工作,css3的作用还不止于此 ...
- postgresql - mac 启动 关闭 postgresql
/Library/PostgreSQL/9.3/bin/pg_ctl -D /Library/PostgreSQL/9.3/data stop /Library/PostgreSQL/9.3/bin/ ...
- 【英语】Bingo口语笔记(68) - come系列
- SSH思路
hibernate的配置写到spring的配置中,用spring管理和调用hibernate的工厂和session等.struts的话,通常有2中.一种是用spring中的一个工厂类代替struts的 ...
- AIX系统管理员--第一章笔记
IBM产品系列 x系类为PC服务器-- e-server x x表示x-architecture 可自由选择运行环境,windows.linux.unix等 p系类为 ...
- Oracle 单实例 迁移到 RAC 实例 -- 使用RMAN 异机恢复
Oracle 官网有关单实例迁移到RAC的一个步骤说明: How to Convert 10g Single-Instance database to 10g RAC using Manual Con ...
- 史上最完整的Android开发工具集合
路径: http://www.apkbus.com/thread-252748-1-1.html
- Linux共享内存(一)
inux系统编程我一直看 <GNU/LINUX编程指南>,只是讲的太简单了,通常是书和网络上的资料结合着来掌握才比较全面 .在掌握了书上的内容后,再来都其他资料 . 原文链接 http:/ ...
- hibernate建表多对多建表
Student.java package cn.itcast.hiberate.sh.domain; import java.util.Set; public class Student { priv ...