生活随笔
收集整理的這篇文章主要介紹了
[codevs3311]起床困难综合症
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題目←
wwq:這題你居然沒(méi)一眼切?!
嗯……二進(jìn)制枚舉……
判斷不超過(guò)m的二進(jìn)制數(shù)的每一位是1更優(yōu)還是0更優(yōu)
顯然同時(shí)滿(mǎn)足我們要放0
為了便于判斷大小,從高位到低位枚舉
復(fù)雜度 2*n*log(m)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define LL long long
using namespace std;
const LL MAXN =
100000 +
50;
LL n,m;
struct zt
{LL ch,num;
}ope[MAXN];
string x;
LL len;
LL ans;
LL check(LL loc,LL v)
{
if(v)v <<= loc;
for(LL i =
1;i <= n;i ++){
if(ope[i].ch ==
1){
if((ope[i].num & v) ==
0)v =
0;}
else if(ope[i].ch ==
2){
if(ope[i].num & (
1 << loc))v = (
1 << loc);}
else if(ope[i].ch ==
3){
if(ope[i].num & (
1 << loc))
if(v)v =
0;
else v = (
1 << loc);}}
return v;
}
LL now,maxn;
int main()
{
scanf(
"%lld%lld",&n,&m);
for(LL i =
1;i <= n;i ++){
cin >> x;
if(x ==
"AND"){ope[i].ch =
1;}
else if(x ==
"OR"){ope[i].ch =
2;}
else if(x ==
"XOR"){ope[i].ch =
3;}
scanf(
"%d",&ope[i].num);maxn = max(maxn,ope[i].num);}len = log2(maxn);
for(LL i = len;i >=
0;i --){LL tmp1 = check(i,
1);LL tmp2 = check(i,
0);
if(now + (
1 << i) > m || tmp2 >= tmp1){ans += tmp2;}
else if(tmp1 > tmp2){ans += tmp1;now += (
1 << i);}}
printf(
"%lld",ans);
}
總結(jié)
以上是生活随笔為你收集整理的[codevs3311]起床困难综合症的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。