加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

贪心相关

发布时间:2020-12-16 07:19:25 所属栏目:百科 来源:网络整理
导读:阿狸与桃子的游戏 史上最水黑题? 注意边权下放到点权的时候,不要/2. 输出答案时再/2,以免整数除法带来错误(第一次就是因为这个wa了23333333 1 #includebits/stdc++.h 2 #define LL long long 3 #define maxn 10000+5 4 #define re register int 5 using n

阿狸与桃子的游戏

史上最水黑题?

注意边权下放到点权的时候,不要/2.

输出答案时再/2,以免整数除法带来错误(第一次就是因为这个wa了23333333

 1 #include<bits/stdc++.h>
 2 #define LL long long
 3 #define maxn 10000+5
 4 #define re register int 
 5 using namespace std;
 6 LL sum;
 7 int dian[maxn];
 8 int n,m;
 9 int main()
10 {
11     ios::sync_with_stdio(false);
12     cin>>n>>m;
13     for(re i=1;i<=n;i++)
14     cin>>dian[i],dian[i]*=2;
15     for(re i=1;i<=m;i++)
16     {
17         int u,v,w;
18         cin>>u>>v>>w;
19         dian[u]+=w;
20         dian[v]+=w;
21     }
22     sort(dian+1,dian+n+1);
23     for(re i=1;i<=n;i+=2)
24     sum+=(dian[n-i+1]-dian[n-i]);
25     cout<<sum/2;
26     return 0;
27  } 
阿狸与桃子的游戏

起床困难综合症

比较重要的性质是全0和全1穿过门后能表示出所有的情况(显然?)

然后拆位贪心就可以了

 1 #include<bits/stdc++.h>
 2 #define re register int
 3 using namespace std;
 4 int n,m,t;
 5 char ch[5];
 6 int tmp1,tmp2=-1;
 7 int ans; 
 8 int main()
 9 {
10     cin>>n>>m;
11     for(re i=1;i<=n;i++)
12     {
13         scanf("%s",ch);
14         cin>>t;
15         if(ch[0]==A) tmp1&=t,tmp2&=t;
16         if(ch[0]==O) tmp1|=t,tmp2|=t;
17         if(ch[0]==X) tmp1^=t,tmp2^=t;
18     }
19     for(re i=29;i>=0;i--)
20     {
21         if((tmp1>>i)&1) ans+=(1<<i);
22         else if(((tmp2>>i)&1)&&(1<<i)<=m)
23         ans+=(1<<i),m-=(1<<i);
24     }
25     cout<<ans;
26     return 0;
27 } 
起床困难综合症

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读