暑假集训——cf热身赛部分题有感加其题解

时间:2023-01-23 13:16:56

刚刚开始集训,集训队队长暂时还没有拉专题,而是拉了部分codeforces上过题人数在2000左右的题组成了一场热身赛(其实就是一场练习),花了一天时间终于把它刷完了,其中很多题让我学到了很多骚操作,还有题是问了学长才会的,自己真的是太菜了!

题目链接:http://codeforces.com/contest/879/problem/C

题目:

暑假集训——cf热身赛部分题有感加其题解

暑假集训——cf热身赛部分题有感加其题解

题意:对于任意的一个数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

题目:

暑假集训——cf热身赛部分题有感加其题解

暑假集训——cf热身赛部分题有感加其题解

题意:一辆车在一条长为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

题目:

暑假集训——cf热身赛部分题有感加其题解

暑假集训——cf热身赛部分题有感加其题解

题意:房子发生着火,里面有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. &lbrack;补档&rsqb;暑假集训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&num;6066】「2017 山东一轮集训 Day3」第二题(哈希,二分)

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

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

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

随机推荐

  1. Kafka的消息格式

    Commit Log Kafka储存消息的文件被它叫做log,按照Kafka文档的说法是: Each partition is an ordered, immutable sequence of me ...

  2. Map 迭代 两种方法

    Map 迭代 两种方法 Map<String, String> map=new HashMap<String,String>(); map.put("1", ...

  3. 我的Python成长之路---第一天---Python基础(5)---2015年12月26日(雾霾)

    六.流程控制 与C语言不通的事Python的流程控制的代码块不是用{}花括号表示的,而是用强制缩进来,而且缩进必须一致,官方推荐是使用4个空格,不建议使用使用tab(制表符)做缩进,一是不同的系统ta ...

  4. cisco模拟器之------交换机、路由器、vlan的综合实例

    主要实现功能:a)位于路由器同一侧的不同网段的主机之间实现通信. b)  位于不同路由器的主机之间实现通信. 网络拓扑图: 命令配置: switch0的配置: Switch(config)#vlan ...

  5. redhad安装gcc问题---解决依赖问题

    在安装gcc时需要cpp和cloog-ppl 但是在安装cpp的时候需要这个依赖:  libmpfr.so.1()(64bit) is needed by cpp-4.4.6-3.el6.x86_64 ...

  6. 用python实现的一个自动聊天的机器人

    因为之前想过 如果每天早上微信能够发送天气预报给我,给我老婆多好,然后就动手看网上的教程做了一个可以定时发送天气预报的程序, 最近又想到折腾,做了一个更加详细的版本.但是需要主动操作 具体操作看图. ...

  7. Educational Codeforces Round 46 C - Covered Points Count

    C - Covered Points Count emmm 好像是先离散化一下 注意 R需要+1 这样可以确定端点 emmm 扫描线?瞎搞一下? #include<bits/stdc++.h&g ...

  8. 嵌入式QT应用的窗口大小、位置&comma;QtreeStack的样式

    1.    窗口固定大小 :this->setFixedSize(452,244); 2.窗口固定位置(经试验,触摸屏的鼠标事件不能有效使用) oldPos.setX((800-452)/2); ...

  9. 一、springMVC、freemarker页面半自动静态化

    说明:刚刚接到公司的通知,实现(半自动化),即通过参数控制是否需要静态化页面(哪里我说错了,勿喷!谢谢) 1,请求.do的URL时直接生成对应的.htm文件,并将请求转发到该htm文件 2,*控制某 ...

  10. sqlite时间戳转时间语句&lpar;时间转时间戳&rpar;实例

    sqlite时间戳转时间.时间转时间戳的方法 实现代码: sqlite, 'unixepoch', 'localtime'); +----------------------------------- ...