标签:map blog namespace math put tmp can scanf reset
https://vjudge.net/problem/Gym-100345H
题意:
给出一个图,求图中u能到达v的对数,并且u<v。并且会有更新和查询操作。
思路:
bitset直接暴力,对于每次更新操作之后,再重新计算一遍即可。bitset是真的强大啊!
1 #include<iostream> 2 #include<algorithm> 3 #include<cstring> 4 #include<cstdio> 5 #include<vector> 6 #include<stack> 7 #include<queue> 8 #include<cmath> 9 #include<map> 10 #include<set> 11 #include<bitset> 12 using namespace std; 13 typedef long long ll; 14 typedef pair<int,int> pll; 15 const int INF = 0x3f3f3f3f; 16 const int maxn=200+5; 17 18 int n, m; 19 int ans; 20 bitset<maxn> tmp[maxn],mp[maxn]; 21 22 void solve() 23 { 24 ans=0; 25 for(int i=1;i<=n;i++) tmp[i].reset(); 26 for(int i=n;i>=1;i--) 27 { 28 tmp[i].set(i); 29 for(int j=1;j<i;j++) 30 { 31 if(mp[j][i]) tmp[j]|=tmp[i]; 32 } 33 ans+=tmp[i].count(); 34 } 35 ans-=n; //减去自环 36 } 37 38 int main() 39 { 40 //freopen("in.txt","r",stdin); 41 freopen("settling.in", "r", stdin); 42 freopen("settling.out", "w", stdout); 43 scanf("%d%d",&n,&m); 44 while(m--) 45 { 46 int u,v; 47 scanf("%d%d",&u,&v); 48 mp[u].set(v); 49 } 50 solve(); 51 printf("%d\n",ans); 52 int t; 53 scanf("%d",&t); 54 while(t--) 55 { 56 char op[2]; int u,v; 57 scanf("%s%d%d",op,&u,&v); 58 if(op[0]==‘?‘) 59 { 60 if(tmp[u][v]) puts("YES"); 61 else puts("NO"); 62 } 63 else if(op[0]==‘+‘) 64 { 65 mp[u].set(v); 66 solve(); 67 printf("%d\n",ans); 68 } 69 else 70 { 71 mp[u].reset(v); 72 solve(); 73 printf("%d\n",ans); 74 } 75 } 76 return 0; 77 }
Gym - 100345H Settling the Universe Up(bitset)
标签:map blog namespace math put tmp can scanf reset
原文地址:http://www.cnblogs.com/zyb993963526/p/7482251.html