刚刚开始集训,集训队队长暂时还没有拉专题,而是拉了部分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热身赛部分题有感加其题解的更多相关文章

  1. POJ3660 暑假集训-最短路H题floyd

      http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82829#rank#include<iostream> #include& ...

  2. POJ-3126 暑假集训-搜索进阶F题

     http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82828#problem/F 经验就是要认真细心,要深刻理解.num #include& ...

  3. AYIT-2020 609暑假集训第一周周赛题 A - A计划

    可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验.魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老.年迈的国王正是心急如焚,告招天下 ...

  4. 2015UESTC 暑假集训总结

    day1: 考微观经济学去了…… day2: 一开始就看了看一道题目最短的B题,拍了半小时交了上去wa了 感觉自己一定是自己想错了,于是去拍大家都过的A题,十分钟拍完交上去就A了 然后B题写了一发暴力 ...

  5. [补档]暑假集训D5总结

    %dalao 今天又有dalao来讲课,讲的是网络流 网络流--从入门到放弃:7-29dalao讲课笔记--https://hzoi-mafia.github.io/2017/07/29/27/   ...

  6. 暑假集训Day2 互不侵犯(状压dp)

    这又是个状压dp (大型自闭现场) 题目大意: 在N*N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共8个格子. ...

  7. 暑假集训Day1 整数划分

    题目大意: 如何把一个正整数N(N长度<20)划分为M(M>=1)个部分,使这M个部分的乘积最大.N.M从键盘输入,输出最大值及一种划分方式. 输入格式: 第一行一个正整数T(T<= ...

  8. 【LOJ#6066】「2017 山东一轮集训 Day3」第二题(哈希,二分)

    [LOJ#6066]「2017 山东一轮集训 Day3」第二题(哈希,二分) 题面 LOJ 题解 要哈希是很显然的,那么就考虑哈希什么... 要找一个东西可以表示一棵树,所以我们找到了括号序列. 那么 ...

  9. STL 入门 (17 暑假集训第一周)

    快速全排列的函数 头文件<algorithm> next_permutation(a,a+n) ---------------------------------------------- ...

随机推荐

  1. lintcode-170-旋转链表

    170-旋转链表 给定一个链表,旋转链表,使得每个节点向右移动k个位置,其中k是一个非负数 样例 给出链表1->2->3->4->5->null和k=2 返回4-> ...

  2. 工具函数:cookie的添加、获取、删除

    cookie是浏览器存储的命名数据,作用是保存用户的信息,这样我们就可以用这些信息来做一些事了,但是cookie容量很小,只有4kb. 下面是我总结的cookie的添加.获取.删除的函数: cooki ...

  3. 第46天:setInterval与setTimeout的区别

    js的setTimeout方法用处比较多,通常用在页面刷新了.延迟执行了等等.今天对js的setTimeout方法做一个系统地总结. setInterval与setTimeout的区别 说道setTi ...

  4. ASP.NET MVC4中使用bootstrip模态框时弹不出的问题

    最近发现使用在MVC中使用bootstrip的模态框时弹不出来,但单独建立一HTML文件时可以弹出,说明代码没有问题,经过多次测试发现,在MVC的cshtml文件中添加上以下语句就能正常 @{ Lay ...

  5. 【bzoj4008】[HNOI2015]亚瑟王 概率dp

    题目描述 $n$ 张牌,$r$ 轮游戏,每轮从左向右操作,遇到第 $i$ 张牌有 $p_i$ 的概率选中,选中会产生 $d_i$ 的贡献,丢弃掉该牌并结束这一轮,否则继续下一张.问最终的期望贡献. 输 ...

  6. 【zoj2314】Reactor Cooling 有上下界可行流

    题目描述 The terrorist group leaded by a well known international terrorist Ben Bladen is buliding a nuc ...

  7. 前端基础:JavaScript介绍

    JavaScript介绍 一.JavaScript简介 1.在1995年时,由Netscape公司的Brendan Eich,在网景导航者浏览器上首次设计实现二层,因为Netscape与Sun合作,N ...

  8. Python 源码剖析(一)【python对象】

    处于研究python内存释放问题,在阅读部分python源码,顺便记录下所得.(基于<python源码剖析>(v2.4.1)与 python源码(v2.7.6)) 先列下总结:      ...

  9. BZOJ5312:冒险——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=5312 Kaiser终于成为冒险协会的一员,这次冒险协会派他去冒险,他来到一处古墓,却被大门上的守护 ...

  10. HTTPS证书生成方法,也适用于APP

    步骤: 一.登录服务器,创建ioscert目录 cd ~/servers/APP mkdir ioscert 二.cd到ioscert目录下,执行以下命令: 1.openssl genrsa -out ...