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 题意:给你一个数组,删除这个数组中相同的元素, 并且保留右边的元素 ...
随机推荐
- 使用JavaScript的XMLHttpRequest+fromdata 传递blob到后端
需要上传网页录音文件到服务器,写的艰辛,终于好了,C#端的代码失败的留作纪念,JS端也有失败的案例,就不放上来了 JavaScript: var form = new FormData(); form ...
- 基于TP5.1实用案例及教程
推荐<基于TP5.1实用案例及教程>书 目录: 通用封装 Export通用封装Import通用封装配合Import通用封装的ImportBaseVerify类Files通用封装Direct ...
- 记一次paramiko远程连接遇到的坑
背景:工作中遇到了一个问题,需要用到windows向windows连接(文件传发)以及,linux向windows连接(文件传发)的需求. 自然而然会考虑到用paramiko,然而paramiko我用 ...
- Docker最简单入门之(一)——介绍和配置Docker
0. 前言 最近学完了Dokcer,特别记录一下,算是对自己学习成果的一个总结.以便自己能够更好的理解Docker.粗略估计了一下,我大概会分成4个部分,只记录一下常用的操作,至于一些比较难的操作或者 ...
- spark shuffle读操作
提出问题 1. shuffle过程的数据是如何传输过来的,是按文件来传输,还是只传输该reduce对应在文件中的那部分数据? 2. shuffle读过程是否有溢出操作?是如何处理的? 3. shuff ...
- JAVA基础知识(九)Java 异常
Throwable是Error和Exception的基类 Exception(异常) :是程序本身可以处理的异常. Error(错误): 是程序无法处理的错误.这些错误表示故障发生于虚拟机自身.或者发 ...
- n的阶乘 -牛客
题目描述 输入一个整数n,输出n的阶乘(每组测试用例可能包含多组数据,请注意处理) 输入描述: 一个整数n(1<=n<=20) 输出描述: n的阶乘 解题思路 采用递归求解,也可以使用循环 ...
- 为什么我们不用JIRA
很多人问我,缺陷管理工具,为什么不用jira?而去自己造轮子开发一款bug记录系统 缄默如我,原因众多.如果只是3-5分钟就能讲的请的时候,我会先列出什么糟点呢? 1. 收费,一个人一个月的费用差不多 ...
- Bootstrap笔记--快速入门
首先是Bootstrap的简介: 业余了解:下面这个网址可以查询IP地址的地理位置 下面学习:(具体可以参考Bootstrap中文网) 栅格系统 Bootstrap 提供了一套响应式.移动设备优先的流 ...
- 维恩贝特面试JAVA后台开发
1 自我介绍 2 链表和数组区别(数组空间连续,且有下标,查找快,但是增删数据效率不高,链表的空间不连续,查找起来慢,但是对数据的增删效率高,链表可以随意扩大,数组不能) 3 sort方法的实现 (A ...