zoukankan      html  css  js  c++  java
  • POJ-3263 Tallest Cow

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cmath>
     4 #include <stdio.h>
     5 #include <cstring>
     6 #include <string>
     7 #include <cstdlib>
     8 #include <queue>
     9 #include <stack>
    10 #include <set>
    11 #include <vector>
    12 #include <map>
    13 #include <list>
    14 #include <iomanip>
    15  #include <fstream>
    16 using namespace std;
    17 
    18 int ans[10001],pre[10001];
    19 map<pair<int,int>,bool> check;
    20 //const long n=100000; 
    21 int main()
    22 {
    23     int n,i,h,r;
    24     int a,b;
    25  
    26     //读入四个数据。 
    27     scanf("%d%d%d%d",&n,&i,&h,&r);
    28     //奶牛数量,没有用的下标,最高的身高,谁比谁高的指令数 
    29     for(int i=0;i<r;++i)
    30     {
    31         //注意判重 !!
    32         scanf("%d%d",&a,&b); 
    33         if(a>b)
    34         {
    35             int temp=a;
    36             a=b;
    37             b=temp;
    38         }
    39         if(check[make_pair(a,b)])
    40             continue;
    41         if(a!=b)//满足第一次谁看谁,并且由于光是沿直线传播的所以互相看都一样 也不能自己看自己 
    42         {
    43             pre[a+1]--;
    44             pre[b]++;
    45             check[make_pair(a,b)]=true;
    46         }
    47         
    48     }
    49     for(int i=1;i<=n;++i)
    50     {
    51         ans[i]=ans[i-1]+pre[i];
    52         cout<<h+ans[i]<<endl;
    53     }
    54 
    55     
    56     return 0;
    57 }
    View Code

    不知道为什么,之前是bool二维数组判定是否重复,结果vj给我MLE了。提交到洛谷上是ac的。参考洛谷题解之后,把bool改成map,结果就过了。

  • 相关阅读:
    51nod 1185 威佐夫游戏 V2
    51nod 1212 无向图最小生成树
    51nod 1242 斐波那契数列的第N项
    51nod 1240 莫比乌斯函数
    51nod 1256 乘法逆元
    51nod 1264 线段相交
    51nod 1265 四点共面
    51nod 1298 圆与三角形
    51nod 2006 飞行员配对
    CGLIB介绍与原理
  • 原文地址:https://www.cnblogs.com/greenaway07/p/11188334.html
Copyright © 2011-2022 走看看