遮挡判断(模拟)
2015-10-27 16:03
239 查看
遮挡判断
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 907 Accepted Submission(s): 292
[align=left]Problem Description[/align]
在一个广场上有一排沿着东西方向排列的石柱子,阳光从东边以一定的倾角射来(平行光)。有的柱子可能被在他东边的高大的柱子的影子给完全遮挡住了。现在你要解决的问题是求出有多少柱子是没有被完全遮挡住的。
假设每个石柱子是一根细棒,而且都垂直于地面摆放。
[align=left]Input[/align]
输
入包含多组数据。每组数据第一行是一个整数N(0<N<=100000),表示柱子的个数。N=0代表输入结束。接下来有N行,每行是两个整
数,分别给出每根柱子的水平位置X和高度H(X越大,表示越在西边,0<=X<=10000000,0<H<=10000000
保证不会有两根柱子在同一个X坐标上)。最后有一行,以分数的形式给出太阳光与地面的夹角的正切值T/A(1<=A,T<=10)。
[align=left]Output[/align]
对每组数据,输出包含所求数目的一行。
[align=left]Sample Input[/align]
4
0 3
3 1
2 2
1 1
1/1
0
[align=left]Sample Output[/align]
2
提示:
输入数据很多,请用scanf代替cin。
题解:找未被完全遮挡的,只需要找被完全遮挡的就好;
代码:
#include<iostream> #include<algorithm> #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> using namespace std; const int INF=0x3f3f3f3f; const int MAXN=100010; struct Node{ int x,h; double s; }; Node dt[MAXN]; int cmp(Node a,Node b){ return a.x<b.x; } int main(){ int N; int T,A; double ang; while(scanf("%d",&N),N){ for(int i=0;i<N;i++){ scanf("%d%d",&dt[i].x,&dt[i].h); } scanf("%d/%d",&T,&A); ang=1.0*T/A; for(int i=0;i<N;i++)dt[i].s=dt[i].h/ang; sort(dt,dt+N,cmp); int num=0; double t=0; for(int i=0;i<N;i++){ if(dt[i].x+dt[i].s>t)t=dt[i].x+dt[i].s; else num++; } printf("%d\n",N-num); } return 0; }
相关文章推荐
- jQuery学习之旅 Item5 $与jQuery对象
- PLDP 更新日志
- 044.@interface <>遵守正式协议
- 【随机过程】随机过程之泊松过程的推广
- 045.@protocol 委托代理
- 从0开始<十二>:strcpy、strcmp、strcat函数的实现
- jquery实现搜索提示效果
- monkey测试中日志分析和内存泄露分析
- No resource found that matches the given name (at 'layout_toLeftOf' with value '@id/tx_search_friend
- SecureCRT软件的串口模式怎样设置
- jquery实现搜索提示效果
- Autodesk InfraWorks 360 2016.2 Win64 1DVD三维建模和可视化技术
- 046.@try 处理异常
- iOS开发者账号添加子账号
- 软考-分治算法
- 特征选择方法-信息增益
- ListView的基础应用
- 比较经典的Jquery代码
- Linux tty1(ctrl+alt+f1)上下滚屏
- 48.Linked List Cycle II