zoj 3511 Cake Robbery

zoj 3511 Cake Robbery,第1张

zoj 3511 Cake Robbery
#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<algorithm>#include<string>#include<map>#include<set>#include<iostream>#include<vector>#include<queue>using namespace std;#define sz(v) ((int)(v).size())#define rep(i, n) for (int i = 0; i < (n); ++i)#define repf(i, a, b) for (int i = (a); i <= (b); ++i)#define repd(i, a, b) for (int i = (a); i >= (b); --i)#define clr(x) memset(x,0,sizeof(x))#define clrs( x , y ) memset(x,y,sizeof(x))typedef long long lint;const int maxint = -1u>>1;const double esp = 1e-8;const int maxn = 10000 + 10;int n, m;vector<int> e[maxn];int v[maxn];void add(int x, int y){ e[x].push_back(y);}int main(){ while(scanf("%d%d", &n, &m) == 2){ repf(i, 1, n) e[i].clear(); rep(i, m){ int x, y; scanf("%d%d", &x, &y); if(x > y) swap(x, y); add(y, x); } add(n, 1); repf(i, 1, n){ sort(e[i].begin(), e[i].end()); reverse(e[i].begin(), e[i].end()); } memset(v, 0, sizeof(v)); int ans = 0; repf(i, 1, n){ v[i] = v[i - 1] + 1; rep(k, sz(e[i])){ int j = e[i][k]; ans = max(ans, v[i] - v[j] + 1); v[i] = v[j] + 1; } } printf("%dn", ans); } return 0;}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4929354.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-13
下一篇 2022-11-13

发表评论

登录后才能评论

评论列表(0条)

保存