【UVALive 3905】BUPT 2015 newbie practice #2 div2-D-3905 - Meteor
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/D
The famous Korean internet company has provided an internet-based photo service which allows The famous Korean internet company users to directly take a photo of an astronomical phenomenon in space by controlling a high-performance telescope owned by . A few days later, a meteoric shower, known as the biggest one in this century, is expected. has announced a photo competition which awards the user who takes a photo containing as many meteors as possible by using the photo service. For this competition, provides the information on the trajectories of the meteors at their web page in advance. The best way to win is to compute the moment (the time) at which the telescope can catch the maximum number of meteors. You have n meteors, each moving in uniform linear motion; the meteor mi moves along the trajectory pi + t × vi over time t, where t is a non-negative real value, pi is the starting point of mi and vi is the velocity of mi . The point pi = (xi , yi) is represented by X-coordinate xi and Y -coordinate yi in the (X, Y )-plane, and the velocity vi = (ai , bi) is a non-zero vector with two components ai and bi in the (X, Y )-plane. For example, if pi = (1, 3) and vi = (−2, 5), then the meteor mi will be at the position (0, 5.5) at time t = 0.5 because pi + t × vi = (1, 3) + 0.5 × (−2, 5) = (0, 5.5). The telescope has a rectangular frame with the lower-left corner (0, 0) and the upper-right corner (w, h). Refer to Figure 1. A meteor is said to be in the telescope frame if the meteor is in the interior of the frame (not on the boundary of the frame). For example, in Figure 1, p2, p3, p4, and p5 cannot be taken by the telescope at any time because they do not pass the interior of the frame at all. You need to compute a time at which the number of meteors in the frame of the telescope is maximized, and then output the maximum number of meteors. Figure 1 Input Your program is to read the input from standard input. The input consists of T test cases. The number of test cases T is given in the first line of the input. Each test case starts with a line containing two integers w and h (1 ≤ w, h ≤ 100, 000), the width and height of the telescope frame, which are separated by single space. The second line contains an integer n, the number of input points (meteors), 1 ≤ n ≤ 100, 000. Each of the next n lines contain four integers xi , yi , ai , and bi ; (xi , yi) is the starting point pi and (ai , bi) is the nonzero velocity vector vi of the i-th meteor; xi and yi are integer values between -200,000 and 200,000, and ai and bi are integer values between -10 and 10. Note that at least one of ai and bi is not zero. These four values are separated by single spaces. We assume that all starting points pi are distinct. Output Your program is to write to standard output. Print the maximum number of meteors which can be in the telescope frame at some moment. Sample Input 2 4 2 2 -1 1 1 -1 5 2 -1 -1 13 6 7 3 -2 1 3 6 9 -2 -1 8 0 -1 -1 7 6 10 0 11 -2 2 1 -2 4 6 -1 3 2 -5 -1 Sample Output 1 2
题解:(题目这里也有)网上有刘汝佳的题解
代码:
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std; const int maxn = ;
struct Event
{
double x;
int type;
bool operator < (const Event& a) const
{
return x < a.x || (x == a.x && type > a.type);
}
}event[maxn*]; void update(int x, int a, int w, double& l, double& r)
{
if(a == )
{
if(x <= || x >= w)
r = l - ;//无解
}
else if(a > )//0 < x+at < w <=> t > -x/a && t < (w-x)/a
{
l = max(l, -(double)x/a);
r = min(r, (double)(w-x)/a);
}
else if(a < )//0 < x+at < w <=> t < -x/a && t > (w-x)/a
{
l = max(l, (double)(w-x)/a);
r = min(r, -(double)x/a);
}
}
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
int w, h, n, e = ;
scanf("%d %d %d", &w, &h, &n);
for(int i = ; i < n; i++)
{
int x, y, a, b;
scanf("%d %d %d %d", &x, &y, &a, &b);
double l = , r = 1e9;
update(x, a, w, l, r);
update(y, b, h, l, r);
if(l < r)
{
event[e++]= (Event){l, };
event[e++]= (Event){r, };
}
}
sort(event, event+e);
int cnt = ;
int ans = ;
for(int i = ; i < e; i++)
{
if(event[i].type == )
cnt++;
else
cnt--;
ans = max(ans, cnt);
}
printf("%d\n", ans);
}
return ;
}
我的题解:
各种条件的判断,注意不要写错>、<
代码:
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std; int t,n,w,h,ans=,numOfXing,validNum,valid;
double x,y,vx,vy,iT,oT,inTime[],outTime[]; int main()
{
scanf("%d",&t);
while(t--)
{
memset(inTime,,sizeof(inTime));
memset(outTime,,sizeof(outTime));
validNum=;
ans=;
scanf("%d%d%d",&w,&h,&n);
for(int i=; i<=n; i++)
{
valid=;
iT=oT=;
scanf("%lf%lf%lf%lf",&x,&y,&vx,&vy);
if(y<=&&vy<=||y>=h&&vy>=||x<=&&vx<=||x>=w&&vx>=)
valid=;
else if(vy==)
{
if((x<=||x>=w)&&x*vx<=)
iT=min(-x/vx,(w-x)/vx);
oT=max(-x/vx,(w-x)/vx);
}
else if(vx==)
{
if((y<=||y>=h)&&y*vy<=)
iT=min(-y/vy,(h-y)/vy);
oT=max(-y/vy,(h-y)/vy);
}
else
{
if(x<=||x>=w||y<=||y>=h)
{
if(x*vy/vx<y&& y+(w-x)*vy/vx<h||h+x*vy/vx>y&&y+(w-x)*vy/vx>)
iT=max(min(-x/vx,(w-x)/vx),min(-y/vy,(h-y)/vy));
else valid=;
}
oT=min(max(-x/vx,(w-x)/vx),max(-y/vy,(h-y)/vy));
} if(valid)
{
validNum++;
inTime[validNum]=iT;
outTime[validNum]=oT;
}
}
sort(inTime+,inTime+validNum+);
sort(outTime+,outTime+validNum+);
int j=;
numOfXing=;
for(int i=; i<=validNum; i++)
{
numOfXing++;
while(outTime[j]<=inTime[i]&&j<=validNum)
{
j++;
numOfXing--;
}
ans=max(ans,numOfXing);
}
printf("%d\n",ans);
}
}
【UVALive 3905】BUPT 2015 newbie practice #2 div2-D-3905 - Meteor的更多相关文章
- 【CodeForces 312B】BUPT 2015 newbie practice #3A Archer
题 SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the targ ...
- 【CodeForces 605A】BUPT 2015 newbie practice #2 div2-E - Sorting Railway Cars
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/E Description An infinitely lon ...
- 【HDU 4925】BUPT 2015 newbie practice #2 div2-C-HDU 4925 Apple Tree
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/C Description I’ve bought an or ...
- 【UVA 401】BUPT 2015 newbie practice #2 div2-B-Palindromes
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/B A regular palindrome is a str ...
- 【UVA 11078】BUPT 2015 newbie practice #2 div2-A -Open Credit System
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/A In an open credit system, the ...
- 【最大流】ECNA 2015 F Transportation Delegation (Codeforces GYM 100825)
题目链接: http://codeforces.com/gym/100825 题目大意: N(N<=600)个点,每个点有个名字Si,R(R<=200)个生产商在R个点上,F(F<= ...
- 【宽搜】ECNA 2015 D Rings (Codeforces GYM 100825)
题目链接: http://codeforces.com/gym/100825 题目大意: 给你一张N*N(N<=100)的图表示一个树桩,'T'为年轮,'.'为空,求每个'T'属于哪一圈年轮,空 ...
- 【宽搜】ECNA 2015 E Squawk Virus (Codeforces GYM 100825)
题目链接: http://codeforces.com/gym/100825 题目大意: N个点M条无向边,(N<=100,M<=N(N-1)/2),起始感染源S,时间T(T<10) ...
- 【Uvalive 2531】 The K-League (最大流-类似公平分配问题)
[题意] 有n个队伍进行比赛,每场比赛,恰好有一支队伍取胜.一支队伍败.每个队伍需要打的比赛场数相同,给你每个队伍目前已经赢得场数和输得场数,再给你一个矩阵,第 i 行第 j 列 表示队伍 i 和队伍 ...
随机推荐
- UVA-10269 (floyd+dijkstra)
题意: 现在有A个村庄,B个城堡,现在要从1到A+B,有M条路,魔法鞋最多能用K次,每次的长度不超过L,且起点和终点一定是村庄和城堡,而且每次使用魔法鞋不能穿过城堡,问最短时间是多少; 思路: 先用F ...
- HDU 4819 Mosaic --二维线段树(树套树)
题意: 给一个矩阵,每次查询一个子矩阵内的最大最小值,然后更新子矩阵中心点为(Max+Min)/2. 解法: 由于是矩阵,且要求区间最大最小和更新单点,很容易想到二维的线段树,可是因为之前没写过二维的 ...
- flex+AS3编程规范
flex+AS3编程规范 Flex+AS3编码规范 http://www.cnblogs.com/jiahuafu/ 1. 缩写: 尽量避免使用缩写,使用缩写时尽量和Flex保持一致.但要记住一 ...
- -bash: rz: command not found
rz,sz是Linux/Unix同Windows进行ZModem文件传输的命令行工具.优点就是不用再开一个sftp工具登录上去上传下载文件. sz:将选定的文件发送(send)到本地机器rz:运行该命 ...
- Windows环境中Openfire与Spark安装与配置指南
安装软件: openfire3.9.3 spark2.6.3 安装环境: WindowsXP JDK1.6.0_21 Oracle 一.openfire安装 1.安装openfire3.9.3,下载地 ...
- DataGridView 行、列的隐藏和删除
) 行.列的隐藏 [VB.NET] ' DataGridView1的第一列隐藏 DataGridView1.Columns(0).Visible = False ' DataGridView1的第一行 ...
- 【有奖】NOIP普及组模拟赛 个人邀请赛 乐多赛
题目描述 日本数学家角谷有一个猜想:任意一个自然数,经过以下过程,最终会得到1.现在请你打印出任意一个数使用角谷猜想转换为1需要几次. 演变方式: 1.如果这个数为奇数,则将它×3+1.如果这个数为偶 ...
- 10Mybatis_mybatis和hibernate本质区别和应用场景
hibernate:是一个标准的ORM框架(对象关系映射).入门门槛较高,不需要程序写sql语句,sql语句自动生产了. 对sql的优化比较困难. 应用场景:适用与需求变化不多的中小型项目中,比如后台 ...
- SQL2008安装后激活方式以及提示评估期已过解决方法(转)
第一步:进入SQL2008配置工具中的安装中心第二步:再进入维护界面,选择版本升级第三步:进入产品密钥,输入密钥第四步:一直点下一步,直到升级完毕.SQL Server 2008 Developer: ...
- g++编译总结
g++编译&&gdb调试&&coredump调试 一.编译注意细节 1.使用g++编译CPP文件如果用gcc编译C++源文件时,加以下选项:-lstdc++,否则使用了 ...