POJ 3263参考系问题

2022/2/13 23:15:56

本文主要是介绍POJ 3263参考系问题,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 1 Tallest Cow
 2 Time Limit: 2000MS        Memory Limit: 65536K
 3 Total Submissions: 8878        Accepted: 3831
 4 Description
 5 
 6 FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positive integer height (which is a bit of secret). You are told only the height H (1 ≤ H ≤ 1,000,000) of the tallest cow along with the index I of that cow.
 7 
 8 FJ has made a list of R (0 ≤ R ≤ 10,000) lines of the form "cow 17 sees cow 34". This means that cow 34 is at least as tall as cow 17, and that every cow between 17 and 34 has a height that is strictly smaller than that of cow 17.
 9 
10 For each cow from 1..N, determine its maximum possible height, such that all of the information given is still correct. It is guaranteed that it is possible to satisfy all the constraints.
11 
12 Input
13 
14 Line 1: Four space-separated integers: N, I, H and R
15 Lines 2..R+1: Two distinct space-separated integers A and B (1 ≤ A, B ≤ N), indicating that cow A can see cow B.
16 Output
17 
18 Lines 1..N: Line i contains the maximum possible height of cow i.
19 Sample Input
20 
21 9 3 5 5
22 1 3
23 5 3
24 4 3
25 3 7
26 9 8
27 Sample Output
28 
29 5
30 4
31 5
32 3
33 4
34 4
35 5
36 5
37 5
38 Source
39 
40 
41 
42 #include<iostream>
43 #include<cstdio>
44 #include<map> 
45 using namespace std;
46 typedef pair<int,int> pii;
47 const int N=1e4+5;
48 int a[N],b[N];
49 int n,pos,mxh,m;
50 
51 int main()
52 {
53     scanf("%d%d%d%d",&n,&pos,&mxh,&m);
54     map<pii,int>mp;
55     for(int i=1;i<=m;i++)
56     {
57         int u,v;
58         scanf("%d%d",&u,&v);
59         if(u>v)swap(u,v);
60         if(mp[make_pair(u,v)])continue;
61         mp[make_pair(u,v)]=1;
62         a[u+1]--;a[v]++;
63     }
64     for(int i=1;i<=n;i++)
65     {
66         b[i]=a[i]+b[i-1];
67         printf("%d\n",b[i]+mxh);
68     } 
69     return 0;
70 }

 



这篇关于POJ 3263参考系问题的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程