bzoj1648 / P2853 [USACO06DEC]牛的野餐Cow Picnic

P2853 [USACO06DEC]牛的野餐Cow Picnic

你愿意的话,可以写dj。

然鹅,对一个缺时间的退役选手来说,暴力模拟是一个不错的选择。

让每个奶牛都把图走一遍,显然那些被每个奶牛都走过的点就是符合条件的点。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 using namespace std;
 5 #define N 1002
 6 int val[N],in[N],k,n,m,ans;
 7 bool d[N][N],vis[N];
 8 void dfs(int x,int t){
 9     vis[x]=1; val[x]+=t;
10     for(int i=1;i<=n;++i)
11         if(d[x][i]&&!vis[i])
12             dfs(i,t);
13 }
14 int main(){
15     scanf("%d%d%d",&k,&n,&m);
16     for(int q,i=1;i<=k;++i)
17         scanf("%d",&q),++in[q];
18     for(int i=1,q1,q2;i<=m;++i)
19         scanf("%d%d",&q1,&q2),d[q1][q2]=1;
20     for(int i=1;i<=n;++i)
21         if(in[i]){
22             memset(vis,0,sizeof(vis));
23             dfs(i,in[i]);
24         }
25     for(int i=1;i<=n;++i)
26         if(val[i]==k) ++ans;
27     printf("%d",ans);
28     return 0;
29 }

原文地址:https://www.cnblogs.com/kafuuchino/p/10031840.html

时间: 2024-08-29 13:33:21

bzoj1648 / P2853 [USACO06DEC]牛的野餐Cow Picnic的相关文章

洛谷 P2853 [USACO06DEC]牛的野餐Cow Picnic

P2853 [USACO06DEC]牛的野餐Cow Picnic dfs 1 #include<bits/stdc++.h> 2 using namespace std; 3 int n,m,k,p[10000],can[10000]; 4 int w[1000+15][1000+15]; 5 bool vis[10000]; 6 7 void dfs(int pre) 8 { 9 for(int j=1;j<=n;j++) 10 { 11 if(w[pre][j]&&!

洛谷——P2853 [USACO06DEC]牛的野餐Cow Picnic

P2853 [USACO06DEC]牛的野餐Cow Picnic 题目描述 The cows are having a picnic! Each of Farmer John's K (1 ≤ K ≤ 100) cows is grazing in one of N (1 ≤ N ≤ 1,000) pastures, conveniently numbered 1...N. The pastures are connected by M (1 ≤ M ≤ 10,000) one-way path

洛谷P2853 [USACO06DEC]牛的野餐Cow Picnic

题目描述 The cows are having a picnic! Each of Farmer John's K (1 ≤ K ≤ 100) cows is grazing in one of N (1 ≤ N ≤ 1,000) pastures, conveniently numbered 1...N. The pastures are connected by M (1 ≤ M ≤ 10,000) one-way paths (no path connects a pasture to

P2853 [USACO06DEC]牛的野餐Cow Picnic

------------------------- 长时间不写代码了,从学校中抽身出来真的不容易啊 ------------------------ 链接:Miku ----------------------- 这道题的思路就在于建反图,如果每一头牛都能到达的话,那么在反图上,这个点也一定能到达每一头牛. 那么我们的目的就明确了,找到所有能在反图上找到每一头牛的点. ----------------------- #include<iostream> #include<cstdio&g

[USACO06DEC]牛的野餐Cow Picnic DFS

题目描述 The cows are having a picnic! Each of Farmer John's K (1 ≤ K ≤ 100) cows is grazing in one of N (1 ≤ N ≤ 1,000) pastures, conveniently numbered 1...N. The pastures are connected by M (1 ≤ M ≤ 10,000) one-way paths (no path connects a pasture to

[BZOJ1648][Usaco2006 Dec]Cow Picnic 奶牛野餐

1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 781  Solved: 483 [Submit][Status][Discuss] Description The cows are having a picnic! Each of Farmer John's K (1 <= K <= 100) cows is grazing in one of N (1 <= N &

1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐

1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 432  Solved: 270[Submit][Status] Description The cows are having a picnic! Each of Farmer John's K (1 <= K <= 100) cows is grazing in one of N (1 <= N <= 1,000)

BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐( dfs )

直接从每个奶牛所在的farm dfs , 然后算一下.. ---------------------------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #include<vector> #define rep( i ,

【题解】P2854 [USACO06DEC]牛的过山车Cow Roller Coaster

P2854 [USACO06DEC]牛的过山车Cow Roller Coaster 题目描述 The cows are building a roller coaster! They want your help to design as fun a roller coaster as possible, while keeping to the budget. The roller coaster will be built on a long linear stretch of land o