贪心+乱搞——最高的牛http://poj.org/problem?id=3263

貌似只要一次更新就行了

我一开始暴力枚举更新,重复1100大循环貌似就会都符合所有的约束

其实每次在区间【a,b】,【a+1,b-1】每个数减一就行了

同时注意重复区间不要算在内。。。

View Code
#include<stdio.h>

int s[10009];
bool hash[10009][10009];

int main()
{
int n,th,max,m;
while(scanf("%d%d%d%d",&n,&th,&max,&m)!=EOF)
{
int a,b,i,j;

for(i=1;i<=n;i++)
{
s[i]=max;
}

for(i=1;i<=m;i++)
{
scanf("%d%d",&a,&b);
if(hash[a][b]==1)continue;

hash[a][b]=1;
while(s[a]>s[b])
s[a]--;

int ll,rr;
if(a>b){ll=b;rr=a;}
else{ll=a;rr=b;}
for(j=ll+1;j<rr;j++)
{
s[j]--;
}
}


for(i=1;i<=n;i++)
{
printf("%d\n",s[i]);
}
}

return 0;
}

ps:后来想到一个数据

7 1 5 3

1 7

2 6

4 7

结果不对,其实不是结果不对,而是我的数据矛盾了,题意说过数据不会自相矛盾的,囧
ps:题目数据有点问题

5 5 5 2

1 5

5 1

结果应该是

5 4 4 4 5

原文地址:https://www.cnblogs.com/huhuuu/p/2260545.html