【CF】110 Div.1 B. Suspects

这题目乍眼一看还以为是2-sat。其实很水的,O(n)就解了。枚举每个人,假设其作为凶手。观察是否满足条件。
然后再对满足的数目分类讨论,进行求解。

  1 /* 156B */
  2 #include <iostream>
  3 #include <string>
  4 #include <map>
  5 #include <queue>
  6 #include <set>
  7 #include <stack>
  8 #include <vector>
  9 #include <deque>
 10 #include <algorithm>
 11 #include <cstdio>
 12 #include <cmath>
 13 #include <ctime>
 14 #include <cstring>
 15 #include <climits>
 16 #include <cctype>
 17 #include <cassert>
 18 #include <functional>
 19 #include <iterator>
 20 #include <iomanip>
 21 using namespace std;
 22 //#pragma comment(linker,"/STACK:102400000,1024000")
 23 
 24 #define sti                set<int>
 25 #define stpii            set<pair<int, int> >
 26 #define mpii            map<int,int>
 27 #define vi                vector<int>
 28 #define pii                pair<int,int>
 29 #define vpii            vector<pair<int,int> >
 30 #define rep(i, a, n)     for (int i=a;i<n;++i)
 31 #define per(i, a, n)     for (int i=n-1;i>=a;--i)
 32 #define clr                clear
 33 #define pb                 push_back
 34 #define mp                 make_pair
 35 #define fir                first
 36 #define sec                second
 37 #define all(x)             (x).begin(),(x).end()
 38 #define SZ(x)             ((int)(x).size())
 39 #define lson            l, mid, rt<<1
 40 #define rson            mid+1, r, rt<<1|1
 41 
 42 const int maxn = 1e5+5;
 43 int pos[maxn], neg[maxn];
 44 vi P[maxn];
 45 vi N[maxn];
 46 int ans[maxn];
 47 int st[maxn];
 48 char s[3][25] = {
 49     "Not defined",
 50     "Truth",
 51     "Lie"
 52 };
 53 
 54 int main() {
 55     ios::sync_with_stdio(false);
 56     #ifndef ONLINE_JUDGE
 57         freopen("data.in", "r", stdin);
 58         freopen("data.out", "w", stdout);
 59     #endif
 60     
 61     int n, m, x;
 62     int pn = 0, nn = 0;
 63     
 64     scanf("%d %d", &n, &m);
 65     rep(i, 1, n+1) {
 66         scanf("%d", &x);
 67         if (x > 0) {
 68             ++pos[x];
 69             P[x].pb(i);
 70             ++pn;
 71         } else {
 72             x = -x;
 73             ++neg[x];
 74             N[x].pb(i);
 75             ++nn;
 76         }
 77     }
 78     
 79     int tmp;
 80     vi vc;
 81     
 82     rep(i, 1, n+1) {
 83         // i is murder
 84         tmp = pos[i] + nn - neg[i];
 85         if (tmp == m)
 86             vc.pb(i);
 87     }
 88     
 89     int sz = SZ(vc);
 90     if (sz == 1) {
 91         x = vc[0];
 92         rep(i, 1, n+1)
 93             st[i] = -1;
 94         st[x] = 1;
 95     } else {
 96         rep(i, 1, n+1)
 97             st[i] = -1;
 98         rep(i, 0, sz)
 99             st[vc[i]] = 0;
100     }
101     rep(i, 1, n+1) {
102         sz = SZ(P[i]);
103         if (sz && st[i]) {
104             x = st[i]>0 ? 1:2;
105             rep(j, 0, sz)
106                 ans[P[i][j]] = x;
107         }
108         sz = SZ(N[i]);
109         if (sz && st[i]) {
110             x = st[i]<0 ? 1:2;
111             rep(j, 0, sz)
112                 ans[N[i][j]] = x;
113         }
114     }
115     
116     rep(i, 1, n+1)
117         puts(s[ans[i]]);
118     
119     #ifndef ONLINE_JUDGE
120         printf("time = %d.\n", (int)clock());
121     #endif
122     
123     return 0;
124 }

 

posted on 2015-07-22 00:02  Bombe  阅读(275)  评论(0编辑  收藏  举报

导航