刚刚开始集训,集训队队长暂时还没有拉专题,而是拉了部分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. FromHandle临时对象一探究竟

    我们在调用CWnd::GetDlgItem()函数时,MSDN告诉我们:The returned pointer may be temporary and should not be stored f ...

  2. Spring Boot(四)@EnableXXX注解分析

    在学习使用springboot过程中,我们经常碰到以@Enable开头的注解,其实早在Spring3中就已经出现了类似注解,比如@EnableTransactionManagement.@ Enabl ...

  3. 原生js实现自定义alert风格和实现

    2018年6月29 最新更新 添加函数节流,解决多次点击问题,添加单例模式,提高代码性能. <!DOCTYPE html> <html lang="en"> ...

  4. 在linux下如何显示隐藏文件

    #显示所有文件(包含隐藏文件)ls -a #只显示隐藏文件l.或者ls -d .* #在XWindow的KDE桌面中在"查看(View)"菜单里选"显示隐藏文件(Show ...

  5. django为model设置表名

    class redis_data(models.Model):     class Meta:         db_table='redis_data'     key=models.CharFie ...

  6. poj3074-Sodoku

    解数独. 分析 考虑如何把数独解合法的条件转化为经典的01精确覆盖: 每个格子只能填一个数,1-9 每一列刚好填了1-9 每一行刚好填了1-9 每个九宫格刚好填了1-9 也就是说,每个格子,列,行,九 ...

  7. 【bzoj2763】[JLOI2011]飞行路线 分层图最短路

    题目描述 Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在n个城市设有业务,设这些城市分别标记为0到n-1,一共有m种航线,每种航线连接两个城市,并且航线有一定的 ...

  8. [洛谷P4847]银河英雄传说V2

    题目大意:有$n(n\leqslant2\times10^5)$个序列,有$m(m\leqslant2\times10^5)$个操作,分三种: 1. $M\;x\;y:$把$x$所在的序列放在$y$所 ...

  9. [HNOI2012][BZOJ2732] 射箭 [二分+半平面交]

    题面 BZOJ题面 思路 半平面交代码讲解戳这里,用的就是这道题 我们射箭的函数形如$y=Ax^2+Bx$ 考虑每一个靶子$(x_0,y_1,y_2)$,实际上是关于$A,B$的不等式限制条件 我们只 ...

  10. HDU5306:Gorgeous Sequence——题解

    http://acm.hdu.edu.cn/showproblem.php?pid=5306 给一个数组,m次操作: 1:l r x,将a[i](l<=i<=r)=min(a[i],x) ...