刚刚开始集训,集训队队长暂时还没有拉专题,而是拉了部分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-380.两个链表的交叉

    两个链表的交叉 请写一个程序,找到两个单链表最开始的交叉节点. 注意事项 如果两个链表没有交叉,返回null. 在返回结果后,两个链表仍须保持原有的结构. 可假定整个链表结构中没有循环. 样例 下列两 ...

  2. (七)类、超类和子类 ——(多态,动态绑定,final类,类型转换,抽象类)

    java中所有的继承都是公有继承. 在子类中的构造其内可以初始化超类的公有域,但不能初始化超类的私有域. 因此需要在子类构造前的第一行使用super()语句初始化超类的私有域. 如果超类没有不带参数的 ...

  3. YaoLingJump开发者日志(八)V1.1版本完成

    跳跃吧瑶玲下载连接 官网下载(网站服务器不支持10M以上的文件上传-_-||) 百度网盘下载 介绍   忙里偷闲,把之前的工作整理了一下完成V1.1版本,下面是更新! (1)去掉了积分榜. (2)增加 ...

  4. linux 相关的问题

    1,查找当前目录下的文件名,并重定向到文件t中 ls > t mac 下快速补全目录名快捷键tab

  5. [计算机网络] DNS何时使用TCP协议,何时使用UDP协议

    DNS同时占用UDP和TCP端口53是公认的,这种单个应用协议同时使用两种传输协议的情况在TCP/IP栈也算是个另类.但很少有人知道DNS分别在什么情况下使用这两种协议. 先简单介绍下TCP与UDP. ...

  6. 【codevs1404】字符串匹配 KMP

    题目描述 给你两个串A,B,可以得到从A的任意位开始的子串和B匹配的长度.给定K个询问,对于每个询问给定一个x,求出匹配长度恰为x的位置有多少个.N,M,K<=200000 输入 第一行三个数 ...

  7. openstack之neutron

    Neutron neutron主要就是用于网络虚拟化,之前将nova的时候说过,网络部分没有写,因为openstack中的网络属于一个大部分,所以今天咱们就来看看neutron到底是怎么样实现网络虚拟 ...

  8. Codeforces Round #517 Div. 1翻车记

    A:真的懵逼了.冷静了半天之后决定二分一下答案,然后先a安排上尽量小的再贪心地一个个扩大.40min才过.这个做法非常怂的以代码复杂度和时间复杂度为代价换取了比较稳的正确性,事实上由于1~n可以组合出 ...

  9. WPF 进度条ProgressBar

    今天研究了一下wpf的进度条ProgressBar 1.传统ProgressBar WPF进度条ProgressBar 这个控件,如果直接写到循环里,会死掉,界面会卡死,不会有进度.需要把进度条放到单 ...

  10. [51nod1325]两棵树的问题

    description 题面 solution 点分治+最小割. 点分必选的重心,再在树上dfs判交,转化为最大权闭合子图. 可以做\(k\)棵树的情况. code #include<iostr ...