返回顶部

状压dp,松鼠从起点出发,拿到所有坚果,然后返回起点,求最短时间。

UVA10944

松鼠从起点出发,拿到所有坚果,然后返回起点,求最短时间。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<vector>
 5 #include<cstring>
 6 #include<map>
 7 #include<set>
 8 #include<cmath>
 9 #include<queue>
10 #include<bitset>
11 #include<utility>
12 #include<functional>
13 #include<iomanip>
14 #include<sstream>
15 #include<ctime>
16 #include<cassert>
17 #define A first
18 #define B second
19 #define mp make_pair
20 #define pb push_back
21 #define pw(x) (1ll << (x))
22 #define sz(x) ((int)(x).size())
23 #define all(x) (x).begin(),(x).end()
24 #define rep(i,l,r) for(int i=(l);i<(r);i++)
25 #define per(i,r,l) for(int i=(r);i>=(l);i--)
26 #define FOR(i,l,r) for(int i=(l);i<=(r);i++)
27 #define eps 1e-9
28 #define PIE acos(-1)
29 #define cl(a,b) memset(a,b,sizeof(a))
30 #define fastio ios::sync_with_stdio(false);cin.tie(0);
31 #define lson l , mid , ls
32 #define rson mid + 1 , r , rs
33 #define ls (rt<<1)
34 #define rs (ls|1)
35 #define INF 0x3f3f3f3f
36 #define lowbit(x) (x&(-x))
37 #define sqr(a) a*a
38 #define ll long long
39 #define ull unsigned long long
40 #define vi vector<int>
41 #define pii pair<int, int>
42 #define dd(x) cout << #x << " = " << (x) << ", "
43 #define de(x) cout << #x << " = " << (x) << "\n"
44 #define endl "\n"
45 using namespace std;
46 //**********************************
47 int n,m;
48 map<string,int>ids;
49 const int maxn=507;
50 //**********************************
51 inline int id(string s)
52 {
53     if(ids.count(s))return ids[s];
54     return ids[s]=sz(ids);
55 }
56 int f[maxn][maxn];
57 //**********************************
58 int main()
59 {
60     string a,c,d,e,b;
61     cin>>n>>m;
62     FOR(i,1,n){
63         cin>>a>>c>>d>>e>>b;
64         f[id(a)][id(b)]=1;
65     }
66     int g=sz(ids);
67     FOR(k,1,g)FOR(i,1,g)FOR(j,1,g)f[i][j]=f[i][j]||(f[i][k]&&f[k][j]); 
68     FOR(i,1,m){
69         cin>>a>>c>>d>>e>>b;
70 //        cout<<a<<c<<d<<e<<b<<endl;
71 //        de(!ids.count(a)||!ids.count(b));
72 //        de(f[id(a)][id(b)]);
73         if(!ids.count(a)||!ids.count(b))cout<<"Pants on Fire"<<endl;
74         else if(f[id(a)][id(b)])cout<<"Fact"<<endl;
75         else if(f[id(b)][id(a)])cout<<"Alternative Fact"<<endl;
76         else cout<<"Pants on Fire"<<endl;
77     }
78     return 0;
79 }
View Code

 

posted @ 2018-09-14 19:30  牛奶加咖啡~  阅读(127)  评论(0编辑  收藏  举报