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. Spring 源码学习(一)-容器的基础结构

    关注公众号,大家可以在公众号后台回复“博客园”,免费获得作者 Java 知识体系/面试必看资料 展示的代码摘取了一些核心方法,去掉一些默认设置和日志输出,还有大多数错误异常也去掉了,小伙伴想看详细代码 ...

  2. 树莓派 + Windows IoT Core 搭建环境监控系统

    前言:Windows IoT 是微软为嵌入式开发板设计的一种物联网操作系统,运行Windows UWP(C# 开发),可以设计出丰富的交互界面,驱动GPIO,连接一些传感器做有意思的事,本文详细介绍如 ...

  3. 分布式ID系列(3)——数据库自增ID机制适合做分布式ID吗

    数据库自增ID机制原理介绍 在分布式里面,数据库的自增ID机制的主要原理是:数据库自增ID和mysql数据库的replace_into()函数实现的.这里的replace数据库自增ID和mysql数据 ...

  4. 【Java例题】7.3 线程题3-素数线程

    3.素数线程.设计一个线程子类,依次随机产生10000个随机整数(100-999):再设计另一个线程子类,依次对每一个随机整数判断是不是素数,是则显示:然后编写主类,在主函数中定义这两个线程类的线程对 ...

  5. ZDog:简单便捷好玩的的3D设计和动画制作库

    各位老铁,我灰太狼又又又回来了,嘿嘿!!!!最近在忙所以有日子没写博客了,今天带大家看个好玩的东西 这个东西是今天偶尔看到的,是啥呢,难道是漂亮的小姐姐吗?当然是......不可能的了,这个东西其实就 ...

  6. Excel批量导入(导出同理)

    在做JavaWeb中添加数据使我们在所难免会遇到的,在大数据的环境下批量添加和批量删除是必须的,而批量删除只需要获取到我们需要删除的ID就可以了,在批量添加中我们就会遇到问题,问题是得到批量的数据,这 ...

  7. Python 学习笔记(6)— 字符串格式化

    字符串格式化处理 远古写法 以前通常使用运算符号 % ,%s 插入的值 String 类型,%.3f 指插入的值为包含 3 位小数的浮点数: format1 = "%s, %s!" ...

  8. Docker进阶-容器监控cAdvisor+InfluxDB+Granfana

    概述 前面文章介绍使用docker compose组合应用并利用scale快速对容器进行扩容. 由于docker compose启动的服务都在同一台宿主机上,对于一个宿主机上运行多个容器应用时,容器的 ...

  9. Spring Cloud Stream 核心概念

    Spring Cloud Stream简介 Spring cloud stream是一个构建与Spring Boot和Spring Integration之上的框架,方便开发人员快速构建基于Messa ...

  10. Java Selenium (十二) 操作弹出窗口 & 智能等待页面加载完成 & 处理 Iframe 中的元素

    一.操作弹出窗口   原理 在代码里, 通过 Set<String> allWindowsId = driver.getWindowHandles(); 来获取到所有弹出浏览器的句柄, 然 ...