zoukankan      html  css  js  c++  java
  • BestCoder Round #36 (hdu5199)Gunner(水题)

    转载请注明出处: http://www.cnblogs.com/fraud/           ——by fraud

    Gunner

    Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)


    Problem Description
    Long long ago, there is a gunner whose name is Jack. He likes to go hunting very much. One day he go to the grove. There are n birds and n trees. The ith bird stands on the top of the ith tree. The trees stand in straight line from left to the right. Every tree has its height. Jack stands on the left side of the left most tree. When Jack shots a bullet in height H to the right, the bird which stands in the tree with height H will falls.
    Jack will shot many times, he wants to know how many birds fall during each shot.

    a bullet can hit many birds, as long as they stand on the top of the tree with height of H.
     


    Input
    There are multiple test cases (about 5), every case gives n,m in the first line, n indicates there are n trees and n birds, m means Jack will shot m times.

    In the second line, there are n numbers h[1],h[2],h[3],,h[n] which describes the height of the trees.

    In the third line, there are m numbers q[1],q[2],q[3],,q[m] which describes the height of the Jack’s shots.

    Please process to the end of file.

    [Technical Specification]

    1n,m1000000(106)

    1h[i],q[i]1000000000(109)

    All inputs are integers.
     


    Output
    For each q[i], output an integer in a single line indicates the number of birds Jack shot down.
     


    Sample Input
    4 3 1 2 3 4 1 1 4
     


    Sample Output
    1 0 1
    Hint
    Huge input, fast IO is recommended.

    水题

      1 //#####################
      2 //Author:fraud
      3 //Blog: http://www.cnblogs.com/fraud/
      4 //#####################
      5 #include <iostream>
      6 #include <sstream>
      7 #include <ios>
      8 #include <iomanip>
      9 #include <functional>
     10 #include <algorithm>
     11 #include <vector>
     12 #include <string>
     13 #include <list>
     14 #include <queue>
     15 #include <deque>
     16 #include <stack>
     17 #include <set>
     18 #include <map>
     19 #include <cstdio>
     20 #include <cstdlib>
     21 #include <cmath>
     22 #include <cstring>
     23 #include <climits>
     24 #include <cctype>
     25 using namespace std;
     26 #define XINF INT_MAX
     27 #define INF 0x3FFFFFFF
     28 #define MP(X,Y) make_pair(X,Y)
     29 #define PB(X) push_back(X)
     30 #define REP(X,N) for(int X=0;X<N;X++)
     31 #define REP2(X,L,R) for(int X=L;X<=R;X++)
     32 #define DEP(X,R,L) for(int X=R;X>=L;X--)
     33 #define CLR(A,X) memset(A,X,sizeof(A))
     34 #define IT iterator
     35 typedef long long ll;
     36 typedef pair<int,int> PII;
     37 typedef vector<PII> VII;
     38 typedef vector<int> VI;
     39 
     40 int a[1000100];
     41 int b[1000100];
     42 int h[1000100];
     43 int p[1000100];
     44 int ans[1000100];
     45 bool cmp(int x,int y){
     46     if(h[x]==h[y])return x<y;
     47     return h[x]<h[y];
     48 }
     49 int Scan()
     50 {
     51     int res, ch=0;
     52     while(!(ch>='0'&&ch<='9')) ch=getchar();
     53     res=ch-'0';
     54     while((ch=getchar())>='0'&&ch<='9')
     55         res=res*10+ch-'0';
     56     return res;
     57 }
     58 void Out(int a)
     59 {
     60     if(a>9)
     61         Out(a/10);
     62     putchar(a%10+'0');
     63 }
     64 
     65 
     66 int main()
     67 {
     68     ios::sync_with_stdio(false);
     69     int n,m;
     70     while(scanf("%d%d",&n,&m)!=EOF){
     71         for(int i=0;i<n;i++)
     72             a[i]=Scan();
     73         sort(a,a+n);
     74         b[0]++;
     75         int tot=0;
     76         for(int i=1;i<n;i++){
     77             if(a[i]==a[i-1])b[tot]++;
     78             else b[++tot]=1;
     79         }
     80         for(int i=0;i<m;i++)h[i]=Scan();
     81         for(int i=0;i<m;i++)p[i]=i;
     82         sort(p,p+m,cmp);
     83         int j=0;
     84         int k=0;
     85         for(int i=0;i<m;i++){
     86             if(j>=n)break;
     87             while(a[j]<h[p[i]]){
     88                 j++;
     89                 if(j>=n)break;
     90                 if(a[j]!=a[j-1])k++;
     91             }
     92             if(j>=n)break;
     93             if(h[p[i]]==a[j]){
     94                 ans[p[i]]=b[k];
     95                 b[k]=0;
     96             }
     97         }
     98         for(int i=0;i<m;i++){
     99             Out(ans[i]);
    100             puts("");
    101         }
    102     }
    103            
    104     return 0;
    105 }
  • 相关阅读:
    STP配置和选路规则
    Apache(基于端口号)
    Apache(基于主机名)
    Apache(基于IP地址)
    (Apache服务)个人用户主页功能
    c语言实现通讯录,包括增加名字,删除信息,查找,修改,排序
    C语言用函数指针的数组简单实现计算器功能
    指针与数组,指针与函数之间的关系
    循环
    SQLite不支持的SQL语法总结
  • 原文地址:https://www.cnblogs.com/fraud/p/4397197.html
Copyright © 2011-2022 走看看