牛客练习赛22 C 简单瞎搞题
//位运算
// & 都是1 才是 1
// | 都是0 才是0
// ^ 不一样才是1
#include <iostream>
#include <cstdio>
#include <bitset>
using namespace std;
const int N=1e6+;
bitset<N>dp[];
int main()
{
dp[][]=;
int n,l,r;
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d%d",&l,&r);
dp[i].reset();//清0
for(int j=l;j<=r;j++){
dp[i]|=dp[i-]<<j*j;//用1的个数来代表种类数
//加上某个数就要左移几位,
//eg 第3位是1,那么就表示此时2是当下和的一个数
}
}
printf("%d\n",dp[n].count());//有几个1
return ;
} // 这是一个讲解bitset 的博客 https://www.cnblogs.com/magisk/p/8809922.html
ll x=(ll)(1ll<<)-;
cout<<x<<endl;
^-1
int : 2.14*10^9 2147483647==2^31-1(可以用int)
ll : 9.2*10^18
2^60 10^18
2^30 10^9
2^64 1.8*10^19
牛课练习赛23 C 托米的位运算 托米完成了1317的上一个任务,十分高兴,可是考验还没有结束
说话间1317给了托米 n 个自然数 a1... an, 托米可以选出一些带回家,但是他选出的数需要满足一些条件
设托米选出来了k 个数 b1,b2... bk, 设这个数列 b 的给值为 b 中所有数按位与的结果,如果你能找到一个整除 b 的最大的 2v,(v≥ ), 则设定 v 为这个数列的给价,如果不存在这样的 v,则给价值为 -, 希望托米在最大化给价的情况下,最大化 k
输入描述:
第一行输入一个整数 n, 第二行输入 a1...an
输出描述:
第一行输出最大的整数 k, 第二行输出 k 个整数 b1... bk, 按原数列的相对顺序输出 (如果行末有额外空格可能会格式错误)
示例1
输入
复制 输出
复制 备注:
n≤ , a1... an < #include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <string>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N=1e5+;
const ll M=(ll)(1ll<<)-;
vector<int>ve;
int n,a[N];
int main()
{
scanf("%d",&n);
ll sum=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
if(!sum){
printf("%d\n",n);
for(int i=;i<=n;i++){
printf("0%c",i==n?'\n':' ');
}
return ;
} //从大到小枚举2^v
for(int i=<<;i>=;i>>=){//只要不全为0,就至少i==1
ll ans=M;//111……(31个1)按位与结果还是别的本身
for(int j=;j<=n;j++){
if(a[j]&i) ans&=a[j];
/*举个例子:
2^v==8 ,那么b%8===0,可以为8,16,24,32,40……
首先这些数的末尾至少有3个0.
16,32这样的一定不行,因为v就变大了。
而24,40这样的一定会是8*奇数,也就是二进制的8
对应位一定为1,因此a[j]对应位(8)也一定为1才能让最后
按位与的结果为(对应位为1).
当然这些数一定要>=i,因为小于i的按位与结果为0.
而且要让所有的满足当下条件的a[j]都参与到按位与
因为此时的结果不成立的话,那么所有的a[j]至少某一位全为1(最后
3位中的一个,v==3时)。因此用更少的a[j]就更不可能了。
*/
}
if(ans%i==){
for(int k=;k<=n;k++){
if(a[k]&i) ve.push_back(a[k]);//因为v时由大到小遍历的
}
printf("%d\n",ve.size());
for(int z=;z<ve.size();z++){
printf("%d%c",ve[z],z==ve.size()-?'\n':' ');
}
return ;
}
}
}
- 128536K
Dlsj is competing in a contest with n (0 < n \le 20)n(0<n≤20) problems. And he knows the answer of all of these problems.
However, he can submit ii-th problem if and only if he has submitted (and passed, of course) s_isi problems, the p_{i, 1}pi,1-th, p_{i, 2}pi,2-th, ......, p_{i, s_i}pi,si-th problem before.(0 < p_{i, j} \le n,0 < j \le s_i,0 < i \le n)(0<pi,j≤n,0<j≤si,0<i≤n) After the submit of a problem, he has to wait for one minute, or cooling down time to submit another problem. As soon as the cooling down phase ended, he will submit his solution (and get "Accepted" of course) for the next problem he selected to solve or he will say that the contest is too easy and leave the arena.
"I wonder if I can leave the contest arena when the problems are too easy for me."
"No problem."
—— CCF NOI Problem set
If he submits and passes the ii-th problem on tt-th minute(or the tt-th problem he solve is problem ii), he can get t \times a_i + b_it×ai+bi points. (|a_i|, |b_i| \le 10^9)(∣ai∣,∣bi∣≤109).
Your task is to calculate the maximum number of points he can get in the contest.
Input
The first line of input contains an integer, nn, which is the number of problems.
Then follows nn lines, the ii-th line contains s_i + 3si+3 integers, a_i,b_i,s_i,p_1,p_2,...,p_{s_i}ai,bi,si,p1,p2,...,psias described in the description above.
Output
Output one line with one integer, the maximum number of points he can get in the contest.
Hint
In the first sample.
On the first minute, Dlsj submitted the first problem, and get 1 \times 5 + 6 = 111×5+6=11 points.
On the second minute, Dlsj submitted the second problem, and get 2 \times 4 + 5 = 132×4+5=13 points.
On the third minute, Dlsj submitted the third problem, and get 3 \times 3 + 4 = 133×3+4=13 points.
On the forth minute, Dlsj submitted the forth problem, and get 4 \times 2 + 3 = 114×2+3=11 points.
On the fifth minute, Dlsj submitted the fifth problem, and get 5 \times 1 + 2 = 75×1+2=7 points.
So he can get 11+13+13+11+7=5511+13+13+11+7=55 points in total.
In the second sample, you should note that he doesn't have to solve all the problems.
样例输入1复制
5
5 6 0
4 5 1 1
3 4 1 2
2 3 1 3
1 2 1 4
样例输出1复制
55
样例输入2复制
1
-100 0 0
样例输出2复制
0
题目来源
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#define max(x,y) x>=y?x:y
#define lowbit(x) x&(-x)
#define ll long long
const ll inf=9e18;
#define N 50
#define M 1<<21
int n,k,pre[N];
ll a[N],b[N],dp[M];//dp的大小
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%lld%lld%d",&a[i],&b[i],&k);
int x;
for(int j=;j<k;j++)
{
scanf("%d",&x);
pre[i]+=(<<(x-));
//在提交第i个之前要完成的
//如 提交第1个之前要完成的 2 3
//那么 pre[1]=110
}
}
int cnt=(<<n);
for(int i=;i<cnt;i++ ) dp[i]=-inf;
dp[]=0ll;
ll ans=;//题意最小0
//dp[i] :按照i的方法进行可以获得的最大价值
for(int i=;i<cnt;i++)//枚举所有情况
//0 1 1 就包含了1 2|2 1
{
for(int j=;j<n;j++) {
if(i>>j&){ int u=i-(<<j);//提交第j+1个之前已经做的
if((u&pre[j+])==pre[j+]){//把提交第j+1个之前要做的都做了。要加(),==高于& ll val=dp[u]+__builtin_popcount(i)*a[j+]+b[j+];
dp[i]=max(dp[i],val);
ans=max(ans,dp[i]);
}
}
}
}
printf("%lld\n",ans);
return ;
}
牛客练习赛22 C 简单瞎搞题的更多相关文章
- 牛客练习赛43-F(简单容斥)
题目链接:https://ac.nowcoder.com/acm/contest/548/F 题意:简化题意之后就是求[1,n]中不能被[2,m]中的数整除的数的个数. 思路:简单容斥题,求[1,n] ...
- 简单瞎搞题(bitset的操作)
链接:https://www.nowcoder.com/acm/contest/132/C来源:牛客网 题目 一共有 n个数,第 i 个数是 xi xi 可以取 [li , ri] 中任意的一个值. ...
- 牛客练习赛22 简单瞎搞题(bitset优化dp)
一共有 n个数,第 i 个数是 xi xi 可以取 [li , ri] 中任意的一个值. 设 ,求 S 种类数. 输入描述: 第一行一个数 n. 然后 n 行,每行两个数表示 li,ri. 输出 ...
- 牛客 132C 简单瞎搞题 (bitset)
大意: 给定序列$a$的第$i$个元素的取值范围$[L_i,R_i]$, 求$a$的平方和的种类数. 用bitset优化, 复杂度$O(\frac{n^5}{\omega})$ #include &l ...
- 【牛客练习赛22 C】
https://www.nowcoder.com/acm/contest/132/C 题目大意:在n个区间中取出n个数,相加的和一共会出现多少种结果. 题目分析:对于这种挑选数字相加,由于每一步不同的 ...
- 牛客练习赛22C Bitset
牛客练习赛22C 一共有 n个数,第 i 个数是 xi xi 可以取 [li , ri] 中任意的一个值. 设 ,求 S 种类数. 感觉二进制真是一个神奇的东西. #include <iost ...
- 牛客练习赛31 B 赞迪卡之声妮莎与奥札奇 逻辑,博弈 B
牛客练习赛31 B 赞迪卡之声妮莎与奥札奇 https://ac.nowcoder.com/acm/contest/218/B 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 2621 ...
- 牛客练习赛 29 E 位运算?位运算!(线段树)
题目链接 牛客练习赛29E 对$20$位分别建立线段树.首先$1$和$2$可以合起来搞(左移右移其实是等效的) 用个lazy标记下.转移的时候加个中间变量. $3$和$4$其实就是区间$01$覆盖操 ...
- 牛客练习赛48 A· 小w的a+b问题 (贪心,构造,二进制)
牛客练习赛48 A· 小w的a+b问题 链接:https://ac.nowcoder.com/acm/contest/923/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C ...
随机推荐
- 【干货分享】大话团队的GIT分支策略进化史
封面 作为一名85后的技术男,一转眼10年过去了(一不小心暴露了年龄,虽然我叫18岁fantasy),亲手写代码已经是5年前了,目前主要负责公司的软件产品的规划和设计(所以最近写的东西也主要与设计和产 ...
- HTTP1.1中CHUNKED编码解析(转载)
HTTP1.1中CHUNKED编码解析 一般HTTP通信时,会使用Content-Length头信息性来通知用户代理(通常意义上是浏览器)服务器发送的文档内容长度,该头信息定义于HTTP1.0协议RF ...
- 13.JAVA-包package、import使用
1.包的定义 之前我们学习java时,生成的class文件都是位于当前目录中,假如出现了同名文件,则会出现文件覆盖问题,因此就需要设置不同的目录(定义包),来解决同名文件冲突问题. 并且在大型项目中, ...
- 安装vs2013提示必须安装ie10的解决办法
虽说应该直接安装ie10,但试了下并不是很顺利,找到如下解决办法,亲测通过. 新建bat文件,内容如下,右键以管理员身份运行,vs即可正常安装. @ECHO OFF :IE10HACK REG ADD ...
- C#小记
1.背景:用fileinput 上传文件 直接上传文件,但有时会发现,这个不上传文件也是可以携带其他参数的, 如果直接用: uploadFile = context.Request.Files[]; ...
- Oracle listener.ora 设置
- Beginning Python Chapter 1 Notes
James Payne(American)编写的<Beginning Python>中文译作<Python入门经典>,堪称是Python的经典著作. 当然安装Python是很简 ...
- 中国区 Azure 服务和定价模式概述
由世纪互联运营的 Microsoft Azure 是第一个在中国正式商用,符合中国政府相关法规要求的国际化公有云服务.本文剖析了由世纪互联运营的 Microsoft Azure 的运营模式.采购模式. ...
- 在Office 365 添加就地保留用户邮箱
基于客户需求,要求将用户批量添加到Office 365中的现有就地保留.如您所了解的,我们可以通过Exchange在线图形用户GUI界面完成,也可以通过PowerShell完成. 要将用户批量添加到O ...
- Python+selenium之fixtures
fixtures即可以表示测试用例的开始和结束,也可以表示测试类和测试模块的开始和结束. import unittest def setUpModule(): print("test mod ...