首页 > 代码库 > NOI2014 起床困难综合症 day1t1

NOI2014 起床困难综合症 day1t1

感觉NOI题在向简单方向发展,或者说明年会难到暴呢?

 

直接模拟啊,枚举每个二进制数位,看经过变换之后是否为1及为1的条件即可。\( O(nlogm)\)。

然后。。。跪了一个点,第五个死活比标准大一。。。

补码表示真dt,我会告诉你 1 >> 32 = 1吗(你肯定知道)?是我太傻逼了。 

  1 //{HEADS  2 #define FILE_IN_OUT  3 #include <cstdio>  4 #include <cstring>  5 #include <cstdlib>  6 #include <cmath>  7 #include <ctime>  8 #include <algorithm>  9 #include <iostream> 10 #include <fstream> 11 #include <vector> 12 #include <stack> 13 #include <queue> 14 #include <deque> 15 #include <map> 16 #include <set> 17 #include <bitset> 18 #include <complex> 19 #include <string> 20 #define REP(i, j) for (int i = 1; i <= j; ++i) 21 #define REPI(i, j, k) for (int i = j; i <= k; ++i) 22 #define REPD(i, j) for (int i = j; 0 < i; --i) 23 #define STLR(i, con) for (int i = 0, sz = con.size(); i < sz; ++i) 24 #define STLRD(i, con) for (int i = con.size() - 1; 0 <= i; --i) 25 #define CLR(s) memset(s, 0, sizeof s) 26 #define SET(s, v) memset(s, v, sizeof s) 27 #define mp make_pair 28 #define pb push_back 29 #define PL(k, n) for (int i = 1; i <= n; ++i) { cout << k[i] << ‘ ‘; } cout << endl 30 #define PS(k) STLR(i, k) { cout << k[i] << ‘ ‘; } cout << endl 31 using namespace std; 32 typedef long long LL; 33 typedef double DB; 34 typedef pair<int, int> i_pair; 35 const int INF = 0x3f3f3f3f; 36 //} 37  38 const int maxn = 1e5 + 100; 39 int ope[maxn], n, m; 40 bitset<33> t[maxn]; 41 char op[10]; 42  43 int me[40][2]; 44  45 int main() { 46     freopen("sleep.in", "r", stdin); 47     freopen("sleep.out", "w", stdout); 48  49     scanf("%d%d", &n, &m); 50     for(int i = 1; i <= n; ++i) { 51         int tmp; 52         scanf("%s %d", op, &tmp); 53         t[i] = tmp; 54     //    printf("%s\n", t[i].to_string().c_str()); 55         if(strcmp(op, "OR") == 0) { 56             ope[i] = 0; 57         } else if(strcmp(op, "AND") == 0) { 58             ope[i] = 1; 59         } else { 60             ope[i] = 2; 61         } 62     } 63     for(int i = 0; i <= 32; ++i) { 64         int init = 1; 65         for(int j = 1; j <= n; ++j) { 66             if(init == 1) { 67                 if(ope[j] == 0) { 68                     init = 1; 69                 } else if(ope[j] == 1) { 70                     if(t[j][i] == 0) { 71                         init = 0; 72                     } else if(t[j][i] == 1) { 73                         init = 1; 74                     } 75                 } else { 76                     if(t[j][i] == 0) { 77                         init = 1; 78                     } else if(t[j][i] == 1) { 79                         init = 0; 80                     } 81                 } 82             } else if(init == 0) { 83                 if(ope[j] == 0) { 84                     if(t[j][i] == 1) { 85                         init = 1; 86                     } 87                 } else if(ope[j] == 1) { 88                     if(t[j][i] == 0) { 89                         init = 0; 90                     } else if(t[j][i] == 1) { 91                         init = 0; 92                     } 93                 } else { 94                     if(t[j][i] == 0) { 95                         init = 0; 96                     } else if(t[j][i] == 1) { 97                         init = 1; 98                     } 99                 }100             }101         }102         me[i][1] = init;103         init = 0;104         for(int j = 1; j <= n; ++j) {105             if(init == 1) {106                 if(ope[j] == 0) {107                     init = 1;108                 } else if(ope[j] == 1) {109                     if(t[j][i] == 0) {110                         init = 0;111                     } else if(t[j][i] == 1) {112                         init = 1;113                     }114                 } else {115                     if(t[j][i] == 0) {116                         init = 1;117                     } else if(t[j][i] == 1) {118                         init = 0;119                     }120                 }121             } else if(init == 0) {122                 if(ope[j] == 0) {123                     if(t[j][i] == 1) {124                         init = 1;125                     }126                 } else if(ope[j] == 1) {127                     if(t[j][i] == 0) {128                         init = 0;129                     } else if(t[j][i] == 1) {130                         init = 0;131                     }132                 } else {133                     if(t[j][i] == 0) {134                         init = 0;135                     } else if(t[j][i] == 1) {136                         init = 1;137                     }138                 }139             }140         }141         me[i][0] = init;142     }143     int ans = 0;144     int bit = 31;145     /* 卧槽!!吧bit改成32就wa了一个点146      * 出题人真良心没卡我147      * 不然就10分了QAQ148      * */149     bool free_flag = false;150     for(int i = bit; 0 <= i; --i) {151         if(free_flag) {152             if(me[i][0] == 1 || me[i][1] == 1) {153                 ans += (1 << i);154             }155             continue;156         }157         if(me[i][0] == 1) {158             ans += (1 << i);159             if((m >> i) & 1) {160                 free_flag = true;161             }162         } else if(me[i][1] == 1) {163             if((m >> i) & 1) {164                 ans += (1 << i);165             }166         } else if((m >> i) & 1) {167             free_flag = true;168         }169     }170     printf("%d\n", ans);171     fclose(stdin);172     fclose(stdout);173     return 0;174 }
巨丑无比的代码