CodeForces Round #498 div3
A:
题目没读, 啥也不会的室友帮我写的。
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9+;
const int N = 1e5+; int main(){
///Fopen;
int a;
cin>>a;
int b[a];
for(int i=;i<a;i++){
cin>>b[i];
}
for(int i=;i<a;i++){
if(b[i]%==) b[i]=b[i]-;
}
for(int i=;i<a;i++){
cout<<b[i]<<' ';
}
return ;
}
A
B:
题意:一共有n个任务,m天内完成,每个任务必须都要完成,并且不能重复完成,还要按顺序完成,每天能获得的利润为当天任务最大的那个利润,现在划分每天完成的任务数量, 来获得最大的总利润。
题解:选出利润最大的m个任务, 然后每天都包含其中一个就好了。
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9+;
const int N = 1e5+;
pll p[N];
int vis[N];
int main(){
///Fopen;
int n, m;
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++){
scanf("%d", &p[i].fi);
p[i].se = i;
}
sort(p+, p++n);
int ans = ;
for(int i = n; i >= n - m + ; i--){
ans += p[i].fi;
vis[p[i].se] = ;
}
printf("%d\n", ans);
int cnt = ;
for(int i = ; i <= n; i++){
cnt++;
if(vis[i]){
m--;
if(m == ) cnt += (n-i);
printf("%d ", cnt);
cnt = ;
}
}
return ;
}
B
C:
题意:给你一堆数列,现在将他们分成连续的3堆,可以为空,现在要求第一堆和最后一堆相等的情况下,最大的第一堆值是多少。
题解:左右开始选,左边大了就右边加上一个新的数,右边大了就左边加上一个新的数,每次相等就记录答案。
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9+;
const int N = 2e5+;
LL d[N];
int main(){
///Fopen;
int n;
scanf("%d", &n);
for(int i = ; i <= n; i++)
scanf("%I64d", &d[i]);
LL sum1 = , sum3 = ;
int i = , j = n;
sum1 = d[];
sum3 = d[n];
LL ans = ;
while(i < j){
if(sum1 == sum3){
ans = sum1;
sum1 += d[++i];
}
else if(sum1 < sum3) sum1 += d[++i];
else if(sum1 > sum3) sum3 += d[--j]; }
cout << ans << endl;
return ;
}
C
D:
题意:给你2个等长的字符串A B,现在可以对于A B串里面的交换对称位置的字符,也可以交换AB同一位置的字符, 然后对于A串还有一个魔法操作就是选择一个位置上的字符,将这个字符改变成其他任意一个字符。现在求先交换字符位置后,要使得这2个串完全相等需要的魔法操作数是多少。
题解:我们可以发现,对于一个位置来说有其他3个位置是对应的,那么我们从前面往后面扫, 如果这一个位置的AB上的字符都对到了, 那么我们就不对这个位置上的字符进行处理, 然后如果不对, 我们看一下A的对称位置上的字符是不是能和B匹配, 如果可以就将A的2个字符交换, 如果不行我们再看看B的对称位置上的字符是不是和改位置上的字符相等, 如果是, 那么交换该位置的A 和 对称位置上的B。
最后我们再看看AB串相同的位置有多少个字符不相等, 就是答案了。
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9+;
const int N = 1e5+;
char a[N], b[N];
int main(){
///Fopen;
int n;
scanf("%d", &n);
scanf("%s", a+);
scanf("%s", b+);
for(int i = ; i <= n; i++){
if(a[i] == b[i]) continue;
int j = n - i + ;
if(a[j] == b[i]) swap(a[j], a[i]);
if(b[j] == b[i]) swap(a[i], b[j]);
}
int ans = ;
for(int i = ; i <= n; i++){
ans += (a[i] != b[i]);
}
cout << ans << endl;
return ;
}
D
看了一眼好友列表里面的代码, 就我的最简单了, 233。
E:
题意:一个公司里面有n个员工, 1号员工为Boss, 然后其他n-1个人都有一个直接上级, 然后上级的上级也算上级, 然后每次一个人接到任务, 都会将任务传递给所有下级, 现在有q次询问,输入一个u k
要求输出第u个员工收到命令后, 第k个收到命令的员工的编号是多少, 如果没有第k个收到命令的员工就输出-1。
题解:dfs序,记录一下开始的dfs序和结束的dfs序, 然后每次询问的时候, 判断一下,有没有第k个员工, 如果有用dfs序输出那个员工的编号就是答案了。
注意的就是链式前向星是倒着遍历边的, 所以如果使用链式前向星要换一个顺序建边。
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9+;
const int N = 2e5+;
int in[N], out[N];
vector<int> son[N];
int ans[N];
int tot = ;
void dfs(int u){
ans[++tot] = u;
in[u] = tot;
for(int i = ; i < son[u].size(); i++)
dfs(son[u][i]);
out[u] = tot;
}
int main(){
///Fopen;
int n, m, u;
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++){
scanf("%d", &u);
son[u].pb(i);
}
dfs();
int v, k;
while(m--){
scanf("%d%d", &v, &k);
if(out[v] < in[v] + k - )
printf("-1\n");
else{
printf("%d\n", ans[in[v]+k-]);
}
}
return ;
}
E
F:
题意:从[1,1] 走到 [n, m] 的位置, 只能朝右和朝下走, 将路过的值都 xor 起来, 最后求到达[n, m]的时候 xor 的值为k的方案数是多少。
题解:如果直接走到n,m的状态数太多, 所以我们将步数对半分, 从[1,1]开始走一半的步数, 从[n,m]开始走剩下的步数, 然后停下来的时候再统计答案。
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = ;
map<LL, int> mp[N][N];
LL a[N][N];
int n, m;
LL k;
void dfs1(int x, int y, int t, LL now){
if(t == ){
mp[x][y][now]++;
return ;
}
if(x+ <= n) dfs1(x+,y,t-,now^a[x][y]);
if(y+ <= m) dfs1(x, y+, t-, now^a[x][y]);
}
LL ans = ;
void dfs2(int x, int y, int t, LL now){
if(t == ){
ans += mp[x][y][now];
return ;
}
if(x-) dfs2(x-,y,t-,now^a[x-][y]);
if(y-) dfs2(x,y-,t-,now^a[x][y-]);
}
int main(){
scanf("%d%d%I64d", &n, &m, &k);
for(int i = ; i <= n; i++)
for(int j = ; j <= m; j++)
scanf("%I64d", &a[i][j]);
int t = n + m - ;
dfs1(,,t/,);
dfs2(n,m,t-t/,k^a[n][m]);
cout << ans << endl;
return ;
}
F
CodeForces Round #498 div3的更多相关文章
- 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3
◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...
- CodeForces Round #527 (Div3) B. Teams Forming
http://codeforces.com/contest/1092/problem/B There are nn students in a university. The number of st ...
- CodeForces Round #527 (Div3) D2. Great Vova Wall (Version 2)
http://codeforces.com/contest/1092/problem/D2 Vova's family is building the Great Vova Wall (named b ...
- CodeForces Round #527 (Div3) D1. Great Vova Wall (Version 1)
http://codeforces.com/contest/1092/problem/D1 Vova's family is building the Great Vova Wall (named b ...
- CodeForces Round #527 (Div3) C. Prefixes and Suffixes
http://codeforces.com/contest/1092/problem/C Ivan wants to play a game with you. He picked some stri ...
- CodeForces Round #527 (Div3) A. Uniform String
http://codeforces.com/contest/1092/problem/A You are given two integers nn and kk. Your task is to c ...
- CodeForces Round #498 Div.3 A. Adjacent Replacements
http://codeforces.com/contest/1006/problem/A Mishka got an integer array aa of length nn as a birthd ...
- Codeforces Round #498 (Div. 3) 简要题解
[比赛链接] https://codeforces.com/contest/1006 [题解] Problem A. Adjacent Replacements [算法] 将序列中的所有 ...
- CodeForces Round#480 div3 第2场
这次div3比上次多一道, 也加了半小时, 说区分不出1600以上的水平.(我也不清楚). A. Remove Duplicates 题意:给你一个数组,删除这个数组中相同的元素, 并且保留右边的元素 ...
随机推荐
- oracle 删除用户,提示“无法删除当前已连接的用户”
1. 首先查询出该用户的登录情况,注意用户名必须是大写 SQL> select username,sid,serial# from v$session where username = 'XST ...
- Docker最简单入门之(一)——介绍和配置Docker
0. 前言 最近学完了Dokcer,特别记录一下,算是对自己学习成果的一个总结.以便自己能够更好的理解Docker.粗略估计了一下,我大概会分成4个部分,只记录一下常用的操作,至于一些比较难的操作或者 ...
- 【Python】狂蟒来袭 | 使用Anaconda搭建Python开发环境
这段时间转了一个小圈圈,发现又回来了,瞎忙.想要学习数据挖掘的小伙伴一定得对机器学习有所了解吧,我之前看过几页周志华老师的西瓜书,但终没能坚持下来. 人生处处是起点,什么时候都不晚.记此笔记以分享与督 ...
- Linux常用命令之压缩解压
压缩是一种通过特定的算法来减小计算机文件大小的机制.这种机制对网络用户是非常有用和高效的,因为它可以减小文件的字节总数,使文件能够通过互联网实现更快传输,此外还可以减少文件的磁盘占用空间.下面简介下z ...
- IDEA+maven搭建scala开发环境(spark)(半转载)
以下内容部分来自于https://zhuanlan.zhihu.com/p/23141509,我尝试了一遍,然后添加了一些图片.. 其实我觉得在IDEA中使用scala插件然后创建project的时候 ...
- Spark 系列(十六)—— Spark Streaming 整合 Kafka
一.版本说明 Spark 针对 Kafka 的不同版本,提供了两套整合方案:spark-streaming-kafka-0-8 和 spark-streaming-kafka-0-10,其主要区别如下 ...
- Windows Server 2008创建域环境
介绍一下域环境搭建,域主要用于中大型企业,小型企业计算机数量不多,而中大型企业计算机比较多,使用域可以方便管理,安全性也比在工作组中安全 1.安装完操作系统默认都属于WORKGROUP工作组. 2.安 ...
- 获取n月后的当前时间
例如用户计算会员的到期日期时间 public static Date getMonthNextOrBeforeDate(int monthNum) { Date dNow = new Date(); ...
- 帝国CMS(EmpireCMS) v7.5后台任意代码执行
帝国CMS(EmpireCMS) v7.5后台任意代码执行 一.漏洞描述 EmpireCMS 7.5版本及之前版本在后台备份数据库时,未对数据库表名做验证,通过修改数据库表名可以实现任意代码执行. 二 ...
- 分布式系统的一致性级别划分及Zookeeper一致性级别分析
最近在研究分布式系统的一些理论概念,例如关于分布式系统一致性的讨论,看了一些文章我有一些不解.大多数对分布式系统一致性的划分是将其分为三类:强一致性,顺序一致性以及弱一致性.强一致性(Strict C ...