在线编程在线课堂在线测评Anycodes在线编程

编程论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

How to use bs4??
本帖最后由 carry0987 于
Double Queue 问题描述 : The new founded Balkan Investment Group Bank (
John 问题描述 : Little John is playing very funny game
linux-command Linux命令大全搜索工具,内容包含Linux命令
Coati 是一款跨平台的代码查看工具,适用于 C/C++ 和 Java。商业软件。特性:1. 索引
系统可承载海量并发,消息收发确认机制 保障消息必达 系统采用动态智
全平台视频监控,支持安卓苹果以及pcweb,支持海康大华等主流dvr,全部源码以及文档 单聊、群聊、商
如何访问类的私有属性? 下面以 TPathData 为例,
问题:从 XE4 以来,Firemonkey 曲线绘图在移动平台不平滑的问题一直令人诟病,提交到官方的 QC 也是族繁不及备载,官方似乎有意的
操作数据库(RODBC)   odbcConnect(dsn, uid="", p
数据模式:mode函数显示任何对象的模式。常见的单个的
系统可承载海量并发,消息收发确认机制 保障消息必达 系统采用动态智
RabbitMQ与PHP(一) 项
Iease团队扩编预备中,盼望能有Ruby或者java工程师加盟。全职兼职都可以。有爱好的伴侣请与我接洽。 邮件:i
ruby 怎么设置装备摆设GTK2,求教指导下!
#include #include #include #include using namespace std; int main() {
标题如图所示: 有n盏灯,编号1~n。一开端灯都是关着的
成熟的消息收发确认机制,支持万人大群 支持开发自定义的消息sdk接口,扩展性超强 支持单/
成熟的消息收发确认机制,支持万人大群 支持开发自定义的消息sdk接口,扩展性超强 支持单/
1. 注意列表和集合的区别 set 列表表现形式: list_1
Ajax   Ajax即“Asynchronous Javascript And
大师好,我比来在做布谷鸟优
分辨提取A和B图像Harris角点,接下来须要对

[HDU杭电] HDU 1025 Constructing Roads In JGShining’s Kingdom-计算几何-[解题报告] C++

[复制链接]
发表于 2016-3-26 22:17:52 | 显示全部楼层 |阅读模式
Constructing Roads In JGShining’s Kingdom


问题描述 :
JGShining’s kingdom consists of 2n(n is no more than 500,000) small cities which are located in two parallel lines.Half of these cities are rich in resource (we call them rich cities) while the others are short of resource (we call them poor cities). Each poor city is short of exactly one kind of resource and also each rich city is rich in exactly one kind of resource. You may assume no two poor cities are short of one same kind of resource and no two rich cities are rich in one same kind of resource. With the development of industry, poor cities wanna import resource from rich ones. The roads existed are so small that they’re unable to ensure the heavy trucks, so new roads should be built. The poor cities strongly BS each other, so are the rich ones. Poor cities don’t wanna build a road with other poor ones, and rich ones also can’t abide sharing an end of road with other rich ones. Because of economic benefit, any rich city will be willing to export resource to any poor one.Rich citis marked from 1 to n are located in Line I and poor ones marked from 1 to n are located in Line II. The location of Rich City 1 is on the left of all other cities, Rich City 2 is on the left of all other cities excluding Rich City 1,  Rich City 3 is on the right of Rich City 1 and Rich City 2 but on the left of all other cities … And so as the poor ones. But as you know, two crossed roads may cause a lot of traffic accident so JGShining has established a law to forbid constructing crossed roads.For example, the roads in Figure I are forbidden.

HDU 1025 Constructing Roads In JGShining’s Kingdom-计算几何-[解题报告] C++

HDU 1025 Constructing Roads In JGShining’s Kingdom-计算几何-[解题报告] C++
In order to build as many roads as possible, the young and handsome king of the kingdom – JGShining needs your help, please help him. ^_^
输入:
Each test case will begin with a line containing an integer n(1 ≤ n ≤ 500,000). Then n lines follow. Each line contains two integers p and r which represents that Poor City p needs to import resources from Rich City r. Process to the end of file.
输出:
For each test case, output the result in the form of sample.
You should tell JGShining what’s the maximal number of road(s) can be built.
样例输入:

  1. 2
  2. 1 2
  3. 2 1
  4. 3
  5. 1 2
  6. 2 3
  7. 3 1
复制代码
样例输出:

  1. Case 1:
  2. My king, at most 1 road can be built.

  3. Case 2:
  4. My king, at most 2 roads can be built.

  5. Hint
  6. Huge input, scanf is recommended.
复制代码
题意: 给你两条街,上面的街编号从 1-n 下面的也是,然后告诉你他们的一些边,    让你从中尽可能选出多的边,使他们两两之间没有交点。分析: LIS 的变形,把一条街看成有序的,求令一条街的最长递增子序列,    因为当 上面 i < j 时 有 f<f[j]。
  1. #include<stdio.h>
  2. #include<string.h>
  3. int d[500005];
  4. int l[500005];
  5. int bis(int len,int x)
  6. {
  7.     int low=0,high=len-1,mid;
  8.     while(low<=high)
  9.     {
  10.         mid=(low+high)>>1;
  11.         if(d[mid]>x)
  12.             high=mid-1;
  13.         else if(d[mid]<x)
  14.             low=mid+1;
  15.         else return mid;
  16.     }
  17.     return low;
  18. }
  19. int main()
  20. {
  21.     int ca=1,len,i,n,a,b,x,pos;
  22.     while(scanf("%d",&n)!=EOF)
  23.     {
  24.         d[0]=5000006;
  25.         len=1;
  26.         for(i=1;i<=n;i++)
  27.         {
  28.             scanf("%d%d",&a,&b);
  29.             l[a]=b;
  30.         }
  31.         for(i=1;i<=n;i++)
  32.         {
  33.             x=l[i];
  34.             if(x>d[len-1])
  35.                 d[len++]=x;
  36.             else
  37.             {
  38.                 pos=bis(len,x);
  39.                 d[pos]=x;
  40.             }
  41.         }
  42.         printf("Case %d:\nMy king, at most %d %s can be built.\n\n",ca++,len,len>1?"roads":"road");
  43.     }
  44.     return 0;
  45. }
复制代码
在线编程(http://www.anycodes.cn)&编程论坛(http://www.52exe.cn)感谢您的支持!
回复

使用道具 举报

发布主题 上个主题 下个主题 快速回复 返回列表 官方QQ群
在线客服
客 服 中 心
群 机 器 人
网站二维码
收 起 客 服

QQ|Archiver|手机版|小黑屋|Anycodes ( ICP14002806Anycodes在线编程

GMT+8, 2018-11-22 01:14 , Processed in 1.652711 second(s), 71 queries .

Powered by Anycodes

© 2001-2013 吉林市群龙科技有限公司 Inc.

快速回复 返回顶部 返回列表