zoukankan      html  css  js  c++  java
  • 遮挡判断(模拟)

    遮挡判断

    Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 907    Accepted Submission(s): 292


    Problem Description
    在一个广场上有一排沿着东西方向排列的石柱子,阳光从东边以一定的倾角射来(平行光)。有的柱子可能被在他东边的高大的柱子的影子给完全遮挡住了。现在你要解决的问题是求出有多少柱子是没有被完全遮挡住的。
    假设每个石柱子是一根细棒,而且都垂直于地面摆放。
     
    Input
    输 入包含多组数据。每组数据第一行是一个整数N(0<N<=100000),表示柱子的个数。N=0代表输入结束。接下来有N行,每行是两个整 数,分别给出每根柱子的水平位置X和高度H(X越大,表示越在西边,0<=X<=10000000,0<H<=10000000 保证不会有两根柱子在同一个X坐标上)。最后有一行,以分数的形式给出太阳光与地面的夹角的正切值T/A(1<=A,T<=10)。
     
    Output
    对每组数据,输出包含所求数目的一行。
     
    Sample Input
    4 0 3 3 1 2 2 1 1 1/1 0
     
    Sample Output
    2 提示: 输入数据很多,请用scanf代替cin。
     题解:找未被完全遮挡的,只需要找被完全遮挡的就好;
    代码:
     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstdio>
     4 #include<cstdlib>
     5 #include<cmath>
     6 #include<cstring>
     7 using namespace std;
     8 const int INF=0x3f3f3f3f;
     9 const int MAXN=100010;
    10 struct Node{
    11     int x,h;
    12     double s;
    13 };
    14 Node dt[MAXN];
    15 int cmp(Node a,Node b){
    16     return a.x<b.x;
    17 }
    18 int main(){
    19     int N;
    20     int T,A;
    21     double ang;
    22     while(scanf("%d",&N),N){
    23         for(int i=0;i<N;i++){
    24             scanf("%d%d",&dt[i].x,&dt[i].h);
    25         }
    26         scanf("%d/%d",&T,&A);
    27         ang=1.0*T/A;
    28         for(int i=0;i<N;i++)dt[i].s=dt[i].h/ang;
    29         sort(dt,dt+N,cmp);
    30         int num=0;
    31         double t=0;
    32         for(int i=0;i<N;i++){
    33             if(dt[i].x+dt[i].s>t)t=dt[i].x+dt[i].s;
    34             else num++;
    35         }
    36         printf("%d
    ",N-num);
    37     }
    38     return 0;
    39 }
  • 相关阅读:
    什么是架构
    intellij idea新建maven项目,一直loading archetype list.....
    maven使用出现的错误
    mock使用中出现的错误
    9个最好用的在线编译/调试工具
    Junit测试中找不到junit.framework.testcase
    mysql图形化界面MySQL_Workbench
    win7下mysql免安装版使用
    qemu安装
    逻辑卷管理
  • 原文地址:https://www.cnblogs.com/handsomecui/p/4914529.html
Copyright © 2011-2022 走看看