暑假集训——cf热身赛部分题有感加其题解
刚刚开始集训,集训队队长暂时还没有拉专题,而是拉了部分codeforces上过题人数在2000左右的题组成了一场热身赛(其实就是一场练习),花了一天时间终于把它刷完了,其中很多题让我学到了很多骚操作,还有题是问了学长才会的,自己真的是太菜了!
题目链接:http://codeforces.com/contest/879/problem/C
题目:


题意:对于任意的一个数x,进行题目给的n种位运算,得到一个新数y,然后让你进行压缩,只进行k次位运算操作(0<=k<=5),也能将x变成y,y的范围为0~1023。
思路:这题需要对位运算十分熟悉,然而我对二进制的了解只是入门,最后还是学长和我说的这题怎么做才A的。应为对于每一个数进行与、或、异或只会对它的二进制进行操作,那么只要最后得到的结果的二进制和题目给的那些操作得到的数的二进制一致,因此只需判断它的每个进位从什么变成了什么即可,最后输出一个总的或的数,异或的数,与的数。因此我们拿两个数,一个二进制全为0(0),一个全是1(1023)进行对比即可确定某个进位进行了哪种操作。
代码实现如下:
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long ll;
typedef unsigned long long ull; #define bug printf("*********\n");
#define debug(x) cout<<"["<<x<<"]"<<endl;
#define IO ios::sync_with_stdio(false),cin.tie(0); const int maxn = 1e5 + ;
const double pi = acos(-);
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f; int n, x;
char s[]; int main() {
cin >>n;
debug(n);
int cnt1 = , cnt2 = ;
while(n--) {
scanf("%s%d", s, &x);
if(s[] == '^') {
cnt1 ^= x;
cnt2 ^= x;
} else if(s[] == '&') {
cnt1 &= x;
cnt2 &= x;
} else {
cnt1 |= x;
cnt2 |= x;
}
}
int AND = , OR = , XOR = ;
int tmp = ;
for(int i = ; i < ; i++) {
int num1 = cnt1 & , num2 = cnt2 & ;
if(num1 == ) {
if(num2 == ) {
AND += tmp;
}
} else {
if(num2 == ) {
XOR += tmp;
AND += tmp;
} else {
OR += tmp;
AND += tmp;
}
}
cnt1 >>= , cnt2 >>= ;
tmp <<= ;
}
printf("3\n& %d\n| %d\n^ %d\n", AND, OR, XOR);
return ;
}
题目链接:http://codeforces.com/contest/864/problem/C
题目:


题意:一辆车在一条长为a的路上开k趟(来算一趟,回去一趟),车可以装b升油(每跑一千米消耗一升),在距离起点f米出有一个加油站,问你最少需要加多少次油。
思路:模拟即可,感觉自己模拟好差,这题WA了2发才A,一开始还以为是规律题,打扰了~
代码实现如下:
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long ll;
typedef unsigned long long ull; #define bug printf("*********\n");
#define FIN freopen("in.txt", "r", stdin);
#define debug(x) cout<<"["<<x<<"]"<<endl;
#define IO ios::sync_with_stdio(false),cin.tie(0); const int maxn = 1e5 + ;
const double pi = acos(-);
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f; ll a, d, f, k, ans; int main() {
scanf("%lld%lld%lld%lld", &a, &d, &f, &k);
ll t = d;
for(ll i = ; i <= k; i++) {
if(i & ) {
if(t < f) {
puts("-1");
return ;
}
t -= f;
if(i == k) {
if(t >= a - f) {
printf("%lld\n", ans);
return ;
} else {
if(d < a - f) {
puts("-1");
return ;
} else {
ans++;
t = d;
}
}
} else {
if(t >= * (a - f)) continue;
else {
if(d < * (a - f)) {
puts("-1");
return ;
} else {
ans++;
t = d;
}
}
}
} else {
if(t < * (a - f)) {
puts("-1");
return ;
}
t -= * (a - f);
if(i == k) {
if(t >= f) {
printf("%lld\n", ans);
return ;
} else {
ans++;
t = d;
}
} else {
if(t < * f) {
if(d < * f) {
puts("-1");
return ;
} else {
ans++;
t = d;
}
}
t -= f;
}
}
// printf("%lld %lld\n", i, ans);
}
printf("%lld\n", ans);
return ;
}
题目链接:http://codeforces.com/contest/864/problem/E
题目:


题意:房子发生着火,里面有N件物品,每件物品救出来需要t的时间,它在d分钟后销毁,价值为p,问你能救出来的物品的总价值为多少,并按顺序打印救的顺序。
思路:01背包+打印路径,dp[i][j]表示第i件物品在第j时被救出来,用vis标记表示第i件物品在j时有没有被救出来,然后用一个vector反转打印路径。
代码实现如下:
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long ll;
typedef unsigned long long ull; #define bug printf("*********\n");
#define FIN freopen("in.txt", "r", stdin);
#define debug(x) cout<<"["<<x<<"]"<<endl;
#define IO ios::sync_with_stdio(false),cin.tie(0); const int maxn = 1e2 + ;
const double pi = acos(-);
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f; int n, ans, k, mx, t;
int dp[maxn][], vis[maxn][];
vector<int> v; struct node {
int t, d, p, id;
bool operator < (const node& x) const {
return d < x.d;
}
}a[maxn]; int main() {
cin >>n;
for(int i = ; i <= n; i++) {
cin >>a[i].t >>a[i].d >>a[i].p;
a[i].id = i;
mx = max(mx, a[i].d);
}
sort(a + , a + n + );
for(int i = ; i <= n; i++) {
for(int j = ; j <= mx; j++) {
dp[i][j] = dp[i-][j];
if(j >= a[i].t && j < a[i].d) {
if(dp[i-][j-a[i].t] + a[i].p > dp[i][j]) {
dp[i][j] = dp[i-][j-a[i].t] + a[i].p;
vis[i][j] = ;
}
}
}
}
for(int i = ; i <= mx; i++) {
if(dp[n][i] > ans) {
ans = dp[n][i];
t = i;
}
}
for(int i = n; i >= ; i--) {
if(vis[i][t]) {
v.push_back(a[i].id);
t = t - a[i].t;
}
}
cout <<ans <<endl;
cout <<v.size() <<endl;
reverse(v.begin(), v.end());
for(int i = ; i < v.size(); i++) {
cout <<v[i] <<" ";
}
cout <<endl;
return ;
}
暑假集训——cf热身赛部分题有感加其题解的更多相关文章
- POJ3660 暑假集训-最短路H题floyd
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82829#rank#include<iostream> #include& ...
- POJ-3126 暑假集训-搜索进阶F题
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82828#problem/F 经验就是要认真细心,要深刻理解.num #include& ...
- AYIT-2020 609暑假集训第一周周赛题 A - A计划
可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验.魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老.年迈的国王正是心急如焚,告招天下 ...
- 2015UESTC 暑假集训总结
day1: 考微观经济学去了…… day2: 一开始就看了看一道题目最短的B题,拍了半小时交了上去wa了 感觉自己一定是自己想错了,于是去拍大家都过的A题,十分钟拍完交上去就A了 然后B题写了一发暴力 ...
- [补档]暑假集训D5总结
%dalao 今天又有dalao来讲课,讲的是网络流 网络流--从入门到放弃:7-29dalao讲课笔记--https://hzoi-mafia.github.io/2017/07/29/27/ ...
- 暑假集训Day2 互不侵犯(状压dp)
这又是个状压dp (大型自闭现场) 题目大意: 在N*N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共8个格子. ...
- 暑假集训Day1 整数划分
题目大意: 如何把一个正整数N(N长度<20)划分为M(M>=1)个部分,使这M个部分的乘积最大.N.M从键盘输入,输出最大值及一种划分方式. 输入格式: 第一行一个正整数T(T<= ...
- 【LOJ#6066】「2017 山东一轮集训 Day3」第二题(哈希,二分)
[LOJ#6066]「2017 山东一轮集训 Day3」第二题(哈希,二分) 题面 LOJ 题解 要哈希是很显然的,那么就考虑哈希什么... 要找一个东西可以表示一棵树,所以我们找到了括号序列. 那么 ...
- STL 入门 (17 暑假集训第一周)
快速全排列的函数 头文件<algorithm> next_permutation(a,a+n) ---------------------------------------------- ...
随机推荐
- Swift-枚举enum理解
//定义一个枚举 //枚举的语法,enum开头,每一行成员的定义使用case关键字开头,一行可以定义多个关键字 enum CompassPoint { case North case South ca ...
- "亿家App"问卷调查分析结果及心得体会
一.问卷问题设计 调查背景:随着现代社会互联网的发展,基于家庭产生的服务项目也越来越多.为增加家庭之间的交流和互助,增加家庭内部.家庭与家庭之间的沟通互助,并利用互联网便捷交流的优势,使家庭在享受服务 ...
- 【Linux】- 文件基本属性
Linux系统是一种典型的多用户系统,不同的用户处于不同的地位,拥有不同的权限.为了保护系统的安全性,Linux系统对不同的用户访问同一文件(包括目录文件)的权限做了不同的规定. 在Linux中我们可 ...
- (转)《linux性能及调优指南》 3.3 内存瓶颈
翻译:Hank (http://blog.csdn.net/fireroll)版权所有,尊重他人劳动成果,转载时请注明作者和原始出处及本声明.原文名称:<Linux Performance an ...
- 读取游标 BEGIN END
USE db_2008 --引入数据库 DECLARE ReadCursor CURSOR --声明一个游标 FOR SELECT * FROM Student OPEN ReadCursor --打 ...
- 基于实现Controller接口的简单Spring工程
这个Spring工程的特点是:实现了Controller接口(这样就可以在url中传参数?,待调查) 一下为代码,可运行. 1,web.xml <servlet> <servlet- ...
- SPD各模块总结
一.用户角色绑定节点 1.库存操作员.库存主管.验货操作员:绑定任一节点 2.采购操作员.公药操作员:只能绑定药库节点 3.退库操作员.药品申领员:绑定药库以外的节点 二.采购计划模块 1.采购计划的 ...
- 【bzoj1821】[JSOI2010]Group 部落划分 Group Kruskal
题目描述 聪聪研究发现,荒岛野人总是过着群居的生活,但是,并不是整个荒岛上的所有野人都属于同一个部落,野人们总是拉帮结派形成属于自己的部落,不同的部落之间则经常发生争斗.只是,这一切都成为谜团了——聪 ...
- Selector 模型
1.服务器端: import selectors import socket sel = selectors.DefaultSelector() #生成一个select对象 def accept(so ...
- LOJ6303:水题——题解
https://loj.ac/problem/6303 题目来自LOJ. 就记一个公式,设f(n,k)为n!里分解得到的k(k为质数)的个数,则f(n,k)=f(n/k,k)+n/k. 证明很好证,显 ...