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. c#将字符串转化为合理的文件名

    string name = System.Text.RegularExpressions.Regex.Replace(url, "[<>/\\|:\"?*]" ...

  2. webpack4核心模块tapable源码解析

    _ 阅读目录 一:理解Sync类型的钩子 1. SyncHook.js 2. SyncBailHook.js 3. SyncWaterfallHook.js 4. SyncLoopHook.js 二: ...

  3. zookeeper 集群配置

    安装前要先确保配置好 jdk,这里不在讲述 一. 将zookeeper 安装包下载到你想要的目录 下载地址:http://mirrors.hust.edu.cn/apache/zookeeper/ m ...

  4. MySQL一键生成实体文件的神器-ginbro

    Java转过来的同学对Mybatis的使用肯定不陌生,特别是对一堆表去生成相应的dao和entity的时候使用Mybatis generator所带来的感触,无比深刻.前面我们也讲过原生的数据库使用, ...

  5. python3学习-Queue模块

    python标准库中带有一个Queue模块,顾名思义,队列.该模块也衍生出一些基本队列不具有的功能. 我们先看一下队列的方法: put 存数据 get 取数据 empty 判断队列是否为空 qsize ...

  6. 【Kubernetes 系列四】Kubernetes 实战:管理 Hello World 集群

    目录 1. 创建集群 1.1. 安装 kubectl 1.1.1. 安装 kubectl 到 Linux 1.1.2. 安装 kubectl 到 macOS 1.1.3. 安装 kubectl 到 W ...

  7. 基于RBAC的权限框架

    RBAC权限框架(Role-Based Access Control)基于角色的权限访问控制的框架,通过用户-角色-权限的关联,非常方便的进行权限管理,在这里不再说明什么是RBAC,请自行百度. 谢谢 ...

  8. myeclipse源码相关操作

    做web开发经常要看别人的jar里的源码才能搞懂别人的想法,但是源码有的时候需要单独下载很麻烦,甚至有的新的jar根本就是没有源码的,那么我们能不能自己制作源码呢. 从jar中提取源码 说白了,提取源 ...

  9. 前端小知识-js

    一.对象冒充 function student(name,age){ this.name = name; this.age = age; this.show = function(){ console ...

  10. Django Mysql数据库-基于双下划线的跨表查询

    一.基于双下划线的跨表查询 Django 还提供了一种直观而高效的方式在查询(lookups)中表示关联关系,它能自动确认 SQL JOIN 联系.要做跨关系查询,就使用两个下划线来链接模型(mode ...