NOI2014 起床困难综合症 day1t1
2014-07-29 18:15
225 查看
感觉NOI题在向简单方向发展,或者说明年会难到暴呢?
直接模拟啊,枚举每个二进制数位,看经过变换之后是否为1及为1的条件即可。\( O(nlogm)\)。
然后。。。跪了一个点,第五个死活比标准大一。。。
补码表示真dt,我会告诉你 1 >> 32 = 1吗(你肯定知道)?是我太傻逼了。
巨丑无比的代码
直接模拟啊,枚举每个二进制数位,看经过变换之后是否为1及为1的条件即可。\( O(nlogm)\)。
然后。。。跪了一个点,第五个死活比标准大一。。。
补码表示真dt,我会告诉你 1 >> 32 = 1吗(你肯定知道)?是我太傻逼了。
//{HEADS #define FILE_IN_OUT #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <ctime> #include <algorithm> #include <iostream> #include <fstream> #include <vector> #include <stack> #include <queue> #include <deque> #include <map> #include <set> #include <bitset> #include <complex> #include <string> #define REP(i, j) for (int i = 1; i <= j; ++i) #define REPI(i, j, k) for (int i = j; i <= k; ++i) #define REPD(i, j) for (int i = j; 0 < i; --i) #define STLR(i, con) for (int i = 0, sz = con.size(); i < sz; ++i) #define STLRD(i, con) for (int i = con.size() - 1; 0 <= i; --i) #define CLR(s) memset(s, 0, sizeof s) #define SET(s, v) memset(s, v, sizeof s) #define mp make_pair #define pb push_back #define PL(k, n) for (int i = 1; i <= n; ++i) { cout << k[i] << ' '; } cout << endl #define PS(k) STLR(i, k) { cout << k[i] << ' '; } cout << endl using namespace std; typedef long long LL; typedef double DB; typedef pair<int, int> i_pair; const int INF = 0x3f3f3f3f; //} const int maxn = 1e5 + 100; int ope[maxn], n, m; bitset<33> t[maxn]; char op[10]; int me[40][2]; int main() { freopen("sleep.in", "r", stdin); freopen("sleep.out", "w", stdout); scanf("%d%d", &n, &m); for(int i = 1; i <= n; ++i) { int tmp; scanf("%s %d", op, &tmp); t[i] = tmp; // printf("%s\n", t[i].to_string().c_str()); if(strcmp(op, "OR") == 0) { ope[i] = 0; } else if(strcmp(op, "AND") == 0) { ope[i] = 1; } else { ope[i] = 2; } } for(int i = 0; i <= 32; ++i) { int init = 1; for(int j = 1; j <= n; ++j) { if(init == 1) { if(ope[j] == 0) { init = 1; } else if(ope[j] == 1) { if(t[j][i] == 0) { init = 0; } else if(t[j][i] == 1) { init = 1; } } else { if(t[j][i] == 0) { init = 1; } else if(t[j][i] == 1) { init = 0; } } } else if(init == 0) { if(ope[j] == 0) { if(t[j][i] == 1) { init = 1; } } else if(ope[j] == 1) { if(t[j][i] == 0) { init = 0; } else if(t[j][i] == 1) { init = 0; } } else { if(t[j][i] == 0) { init = 0; } else if(t[j][i] == 1) { init = 1; } } } } me[i][1] = init; init = 0; for(int j = 1; j <= n; ++j) { if(init == 1) { if(ope[j] == 0) { init = 1; } else if(ope[j] == 1) { if(t[j][i] == 0) { init = 0; } else if(t[j][i] == 1) { init = 1; } } else { if(t[j][i] == 0) { init = 1; } else if(t[j][i] == 1) { init = 0; } } } else if(init == 0) { if(ope[j] == 0) { if(t[j][i] == 1) { init = 1; } } else if(ope[j] == 1) { if(t[j][i] == 0) { init = 0; } else if(t[j][i] == 1) { init = 0; } } else { if(t[j][i] == 0) { init = 0; } else if(t[j][i] == 1) { init = 1; } } } } me[i][0] = init; } int ans = 0; int bit = 31; /* 卧槽!!吧bit改成32就wa了一个点 * 出题人真良心没卡我 * 不然就10分了QAQ * */ bool free_flag = false; for(int i = bit; 0 <= i; --i) { if(free_flag) { if(me[i][0] == 1 || me[i][1] == 1) { ans += (1 << i); } continue; } if(me[i][0] == 1) { ans += (1 << i); if((m >> i) & 1) { free_flag = true; } } else if(me[i][1] == 1) { if((m >> i) & 1) { ans += (1 << i); } } else if((m >> i) & 1) { free_flag = true; } } printf("%d\n", ans); fclose(stdin); fclose(stdout); return 0; }
巨丑无比的代码
相关文章推荐
- BZOJ3668 [NOI2014] 起床困难综合症
- 3668: [Noi2014]起床困难综合症
- BZOJ 3668 [Noi2014]起床困难综合症
- 【BZOJ】3668: [Noi2014]起床困难综合症(暴力)
- BZOJ3668: [Noi2014]起床困难综合症(洛谷P2114)
- 洛谷 P2114 [NOI2014 D1T1] 起床困难综合症 [bitset做法]
- bzoj 3668: [Noi2014]起床困难综合症
- bzoj 3668: [Noi2014]起床困难综合症【贪心】
- Luogu P2114[NOI2014]起床困难综合症 【贪心/位运算】By cellur925
- UOJ #2. 【NOI2014】起床困难综合症 数位DP
- BZOJ 3668: [Noi2014]起床困难综合症 贪心
- 【uoj2】 NOI2014—起床困难综合症
- Luogu 睡觉困难综合征 ([NOI2014]起床困难综合症)
- bzoj3668 [Noi2014] 起床困难综合症 贪心
- #2. 【NOI2014】起床困难综合症
- BZOJ 3668 NOI2014 起床困难综合症 贪心
- 【贪心+位运算】BZOJ3668(Noi2014)[起床困难综合症]题解
- 【BZOJ】3668 [Noi2014]起床困难综合症 贪心
- BZOJ3668: [Noi2014]起床困难综合症|2进制拆分|贪心
- 【bzoj3668】【noi 2014】【起床困难综合症】【贪心】