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