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的更多相关文章

  1. 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3

    ◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #498 (Div. 3) 简要题解

    [比赛链接] https://codeforces.com/contest/1006 [题解] Problem A. Adjacent Replacements        [算法] 将序列中的所有 ...

  9. CodeForces Round#480 div3 第2场

    这次div3比上次多一道, 也加了半小时, 说区分不出1600以上的水平.(我也不清楚). A. Remove Duplicates 题意:给你一个数组,删除这个数组中相同的元素, 并且保留右边的元素 ...

随机推荐

  1. HTML5 第二章 列表和表格和媒体元素

    列表: (1)什么是列表? 列表就是信息资源的一种展示形式. (2)无序列表: 语法: <ul> <li>第1项</li> <li>第2项</li ...

  2. spring-boot项目的docker集成化部署(一)

    目录 spring-boot项目的docker集成化部署 前言 基本思路与方案 基本步骤 准备源码 服务器和基础环境 结语 1. 本文总结: 2. 后期优化: spring-boot项目的docker ...

  3. js 双向绑定数据

    let aaa = []; let bbb = [1,2,3]; let ccc = [0,9,8]; aaa = bbb; //此时aaa与bbb被绑定(aaa指向bbb的指向) ,若使用push则 ...

  4. PHP 的一些底层知识

    本篇内容比较干涩,请自备矿泉水 文章分6个主题进行讲解 PHP运行机制和原理 PHP底层变量数据结构 PHP传值赋值中的COW特性 PHP垃圾回收机制 PHP中数组底层分析 PHP数组函数分类 PHP ...

  5. JavaWeb——Servlet开发1

    Java Servlet是运行在服务器端上的程序,Servlet是Java Servlet包中的一个接口,能够直接处理和相应客户端的请求,也可以将工作委托给应用的其他类. public interfa ...

  6. android ——悬浮按钮及可交互提示

    一.悬浮按钮 FloatingActionButton是Design Support中的一个控件,它会默认colorAccent作为按钮的颜色,还可以给按钮一个图标. 这是没有图标的,这是有图标的. ...

  7. Git使用(码云)

    1.安装git软件(码云/GitHub) 2.码云注册,保存代码 3.创建代码托管仓库,仓库名相当于码云上的文件夹 4.写作业并提交 在作业文件夹上,右键选择‘get bash here’ 在黑框里输 ...

  8. ASP.NET Core on K8S深入学习(3-2)DaemonSet与Job

    本篇已加入<.NET Core on K8S学习实践系列文章索引>,可以点击查看更多容器化技术相关系列文章. 上一篇<3-1 Deployment>中介绍了Deployment ...

  9. .netcore持续集成测试篇之测试方法改造

    系列目录 通过前面两节讲解,我们的测试类中已经有两个测试方法了,总体上如下 public class mvc20 { private readonly HttpClient _client; publ ...

  10. Appium+python自动化(三十二)- 代码写死一时爽,框架重构火葬场 - PageObject+unittest(超详解)

    简介 江湖有言:”代码写死一时爽,框架重构火葬场“,更有人戏言:”代码动态一时爽,一直动态一直爽