1081: 集训队分组
# include
# include
# include
# include
# define N 1005
using namespace std;
vector<int> g[N];
char vis[N];
int bfs(int u)
{
int i, cx, nx, ret;
int Q[N], front, rear;
Q[1] = u;
memset(vis, 0, sizeof(vis));
vis[u] = 1;
front = 1;
rear = 2;
ret = 0;
while (front < rear)
{
cx = Q[front++];
for (i = 0; i < g[cx].size(); ++i)
{
nx = g[cx][i];
if (!vis[nx])
{
Q[rear++] = nx;
vis[nx] = 1;
++ret;
}
}
}
return ret;
}
int main()
{
int i, n, u, v, k, m, cnt;
while (~scanf("%d%d%d", &n, &k, &m))
{
for (i = 1; i <= n; ++i) g[i].clear();
for (i = 0; i < m; ++i)
{
scanf("%d%d", &u, &v);
g[u].push_back(v);
}
cnt = 0;
for(i = 1; i <= n; ++i)
{
if (bfs(i) >= n-k) ++cnt;
if (cnt >= k) break;
}
puts(cnt>=k ? "YES":"NO");
}
return 0;
}
1082: 憧憬一下集训
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MX = 2e4 + 5;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define root 0,10000,1
int MAX[MX << 2], col[MX << 2];
struct Que {
int L, R, top, d;
bool operator<(const Que &b)const {
if(top == b.top) return d > b.d;
return top < b.top;
}
Que(int _top = 0, int _L = 0, int _R = 0, int _d = 0) {
L = _L; R = _R; top = _top; d = _d;
}
} Q[MX];
void push_up(int rt) {
MAX[rt] = max(MAX[rt << 1], MAX[rt << 1 | 1]);
}
void push_down(int rt) {
if(col[rt]) {
col[rt << 1] += col[rt];
col[rt << 1 | 1] += col[rt];
MAX[rt << 1] += col[rt];
MAX[rt << 1 | 1] += col[rt];
col[rt] = 0;
}
}
void update(int L, int R, int d, int l, int r, int rt) {
if(L <= l && r <= R) {
MAX[rt] += d;
col[rt] += d;
return;
}
int m = (l + r) >> 1;
push_down(rt);
if(L <= m) update(L, R, d, lson);
if(R > m) update(L, R, d, rson);
push_up(rt);
}
int main() {
int n;
while(~scanf("%d", &n)) {
memset(MAX, 0, sizeof(MAX));
memset(col, 0, sizeof(col));
for(int i = 1; i <= n; i++) {
int x1, x2, y1, y2;
scanf("%d%d%d%d", &x1, &x2, &y1, &y2);
Q[i] = Que(y1, x1, x2, 1);
Q[i + n] = Que(y2, x1, x2, -1);
}
sort(Q + 1, Q + 1 + 2 * n);
int ans = 0;
for(int i = 1; i <= 2 * n; i++) {
update(Q[i].L, Q[i].R, Q[i].d, root);
ans = max(ans, MAX[1]);
}
printf("%d\n", ans);
}
return 0;
}
1086: 超市购物
#include
#include
#include
using namespace std;
const int MAXN=35;
const int MAXM=2005;
int weight[MAXN][MAXN],value[MAXN][MAXN];
int dp[MAXM];
int main()
{
int k,m;
int c=1;
while(scanf("%d%d",&k,&m)>0)
{
memset(dp,0,sizeof(dp));
memset(weight,0,sizeof(weight));
memset(value,0,sizeof(value));
for(int i=1;i<=k;i++)
{
int n;
scanf("%d",&n);
weight[i][0]=n;
for(int j=1;j<=n;j++)
scanf("%d%d",&weight[i][j],&value[i][j]);
}
for(int i=1;i<=k;i++)
for(int j=m;j>=0;j--)
for(int p=1;p<=weight[i][0];p++)
if(weight[i][p]<=j)
dp[j]=max(dp[j],dp[j-weight[i][p]]+value[i][p]);
printf("Case %d: %d\n\n",c++,dp[m]);
}
return 0;
}
1087: 就多了两分钟
#include
#include
using namespace std;
int main()
{
int h1,m1,h2,m2;
int kase=0;
while(cin>>h1>>m1>>h2>>m2)
{
printf("Day %d: ",++kase);
if(h1>h2||h1==h2&&m1>m2)
{
cout<<"Joking"<<endl;
continue;
}
int t=(h2-h1)*60+m2-m1;
int ans=t/30;
int last=t%30;
if(last)
last=30-t%30;
if(last!=0&&last!=30)
ans++;
cout<" "<endl;
}
return 0;
}