Codeforces Div3 #498 A-F
A. Adjacent Replacements
执行1e9次命令,输出的最后数组的样子
一个奇数执行两次命令 会变回原来的数字
一个偶数只会执行一次命令 变成比自身小1的数
#include<bits/stdc++.h>
#define int long long
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef unsigned long long uLL;
using namespace std;
const int maxn=1e6+;
const int INF=1e15;
int a[maxn];
int32_t main()
{
int n; cin>>n;
for(int i=;i<=n;i++) cin>>a[i];
for(int i=;i<=n;i++)
{
if(a[i]%==) cout<<a[i]<<" ";
else cout<<a[i]-<<" ";
}
}
A.cpp
B. Polycarp's Practice
给出 数组n k 将数组分成k段(每段至少1) 求k段每段中最大数的和的最大值
排序一下 最大的n个数就是数字最大的
将k个最大数标记 我用的map 标记
然后扫一遍输出 第一个标记前的非标记的个数和自身 标记和标记间的个数 最后一个标记和标记间还有标记后的个数
例子
1 2 3 2 1 4 1 5 1 3
mp[3]=1; mp[2]=1; mp[5]=1; 这是被标记的
分成的为 1 2 3 2 1 4 1 5 1 3 三段
#include<bits/stdc++.h>
#define int long long
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef unsigned long long uLL;
using namespace std;
const int maxn=1e6+;
const int INF=1e15;
int a[maxn];
int b[maxn];
map<int,int> mp;
int32_t main()
{
int n,k; cin>>n>>k;
for(int i=;i<=n;i++) {cin>>a[i]; b[i]=a[i];}
sort(a+,a++n);
int ans=; int num=k;
for(int i=n;i>=;i--)
{
if(num) {ans+=a[i]; num--; mp[a[i]]++; }
}
cout<<ans<<endl;
int t=;
for(int i=;i<=n;i++)
{
if(mp[b[i]]&&k!=)
{
cout<<t+<<" "; t=; mp[b[i]]--; k--;
}
else
{
t++;
}
}
cout<<t<<" ";
}
B.cpp
C. Three Parts of the Array
给你一个数组 你分成3段(长度可以为0) 是第一段和最后一段的和相等 求怎么样分让第一段和最大
定义 num1=num3=0;
一个从前往后找 一个从后往前找 谁少谁加 一样就记录答案 都加一个数
#include<bits/stdc++.h>
#define int long long
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef unsigned long long uLL;
using namespace std;
const int maxn=1e6+;
const int INF=1e15;
int a[maxn];
int32_t main()
{
int n; cin>>n;
for(int i=;i<=n;i++) scanf("%d",&a[i]);
int num1=;
int num3=;
int ans=;
int i=;
int j=n+;
while(i+!=j)
{
if(num1==num3)
{
ans=max(num1,num3); if(i+==j) break;
i++;j--; num1+=a[i]; num3+=a[j];
}
else if(num1<num3)
{
i++; num1+=a[i];
}
else if(num1>num3)
{
j--; num3+=a[j];
}
}
if(num1==num3) ans=num1;
cout<<ans<<endl;
}
C.cpp
D. Two Strings Swaps
给你两个字符串 长度一样 修改第一个字符串 再通过变换 让两个字符串一样
变换规则
- Choose any index ii (1≤i≤n1≤i≤n) and swap characters aiai and bibi;
- Choose any index ii (1≤i≤n1≤i≤n) and swap characters aiai and an−i+1an−i+1;
- Choose any index ii (1≤i≤n1≤i≤n) and swap characters bibi and bn−i+1bn−i+1;
找 ai a(n-i) bi ,b(n-i) 中最大有多少对字符一样
当ai=a(n-i) 时特判 bi!=b(n-1) 要修改两个
#include<bits/stdc++.h>
#define int long long
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef unsigned long long uLL;
using namespace std;
const int maxn=1e6+;
const int INF=1e15;
int32_t main()
{
int n; cin>>n;
string ss;cin>>ss;
string tt;cin>>tt;
int ans=; for(int i=;i<n/;i++)
{ int t=;
if(ss[i]==ss[n--i]) t++;
if(tt[i]==tt[n--i]) t++;
else t--;
int w=;
if(ss[i]==tt[i]) w++;
if(ss[n--i]==tt[n--i]) w++;
int k=;
if(ss[i]==tt[n--i]) k++;
if(ss[n-i-]==tt[i]) k++;
int num=MAX(t,w,k);
if(num==) ans+=;
if(num==) ans+=;
}
if(n%==)
{
if(ss[n/]!=tt[n/]) ans++;
}
cout<<ans<<endl; }
D.cpp
E. Military Problem
树不会很会 表述(大家多多见谅)
有一个树
q次询问 问节点 x 是否有 y 个子节点 没有输出 -1 有输出第y个字节点上的书
#include<bits/stdc++.h>
#define int long long
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef unsigned long long uLL;
using namespace std;
const int maxn=1e6+;
const int INF=1e15;
vector<int> tree[maxn];
int vis[maxn];
int sum[maxn];
int s[maxn];
int cnt=;
int dfs(int id)
{
int ans=;
vis[id]=cnt;
s[cnt]=id;
cnt++;
for(int i=;i<tree[id].size();i++)
ans+=dfs(tree[id][i]);
return sum[id]+=ans;
}
int32_t main()
{
int n,p; cin>>n>>p;
for(int i=;i<=n;i++)
{
int a; cin>>a; tree[a].pb(i);
}
dfs();
while(p--)
{
int x,y;
cin>>x>>y;
if(sum[x]<y) cout<<"-1"<<endl;
else
cout<<s[vis[x]+y-]<<endl;
}
}
E.cpp
F. Xor-Paths
从(1,1)到 (n, m) 找路径中所有数的异或为k的道路条数 (只能下 右)
直接dfs会超时 用两端dfs
#include<bits/stdc++.h>
#define int long long
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef unsigned long long uLL;
using namespace std;
const int maxn=+;
const int INF=0x3f3f3f3f;
int a[][];
map<int,int> mp[][];
int n,m,k;
int MAX;
int ans;
void dfs1(int x,int y,int num)
{
num=num^a[x][y];
if(x+y==MAX)
{
mp[x][y][num]++;
}
else
{
int x1=x+;
int y1=y;
if(x1>= && x1<=n && x1>= && y1<=m)
{
dfs1(x1,y1,num);
}
int x2=x;
int y2=y+;
if(x2>= && x2<=n && x2>= && y2<=m)
{
dfs1(x2,y2,num);
}
}
}
void dfs2(int x,int y,int num)
{
if(x+y==MAX)
{
ans+= mp[x][y][num];
}
else
{
num=num^a[x][y];
int x1=x-;
int y1=y;
if(x1>= && x1<=n && x1>= && y1<=m)
{
dfs2(x1,y1,num);
}
int x2=x;
int y2=y-;
if(x2>= && x2<=n && x2>= && y2<=m)
{
dfs2(x2,y2,num);
}
}
}
int32_t main()
{
cin>>n>>m>>k;
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
cin>>a[i][j];
}
}
if(n==&&m==)
{
if(k==a[][]) cout<<<<endl;
else cout<<<<endl;
return ;
} MAX=max(n,m);
dfs1(,,);
dfs2(n,m,k);
cout<<ans<<endl;
}
F.cpp
Codeforces Div3 #498 A-F的更多相关文章
- Codeforces Div3 #501 A-E(2) F以后补
感觉自己有点强迫症 不都写出来就找理由不写题解 http://codeforces.com/contest/1015 题目链接 A. Points in Segments 题目意思 n个线段 ...
- CodeForces Round #498 div3
A: 题目没读, 啥也不会的室友帮我写的. #include<bits/stdc++.h> using namespace std; #define Fopen freopen(" ...
- Codeforces Round #535 (Div. 3) [codeforces div3 难度测评]
hhhh感觉我真的太久没有接触过OI了 大约是前天听到JK他们约着一起刷codeforces,假期里觉得有些颓废的我忽然也心血来潮来看看题目 今天看codeforces才知道居然有div3了,感觉应该 ...
- Codeforces Gym 100500F Problem F. Door Lock 二分
Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/at ...
- Codeforces Gym 100002 Problem F "Folding" 区间DP
Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/ ...
- 树形DP ---- Codeforces Global Round 2 F. Niyaz and Small Degrees引发的一场血案
Aspirations:没有结果,没有成绩,acm是否有意义?它最大的意义就是让我培养快速理解和应用一个个未知知识点的能力. ————————————————————————————————————— ...
- Codeforces Round #498 (Div. 3) 简要题解
[比赛链接] https://codeforces.com/contest/1006 [题解] Problem A. Adjacent Replacements [算法] 将序列中的所有 ...
- codeforces Educational Codeforces Round 24 (A~F)
题目链接:http://codeforces.com/contest/818 A. Diplomas and Certificates 题解:水题 #include <iostream> ...
- Codeforces Gym 100286F Problem F. Fibonacci System 数位DP
Problem F. Fibonacci SystemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...
随机推荐
- Jenkins的安装、启动和配置
一.Jenkins的安装 1.前提条件:已经成功安装了JDK,因为jenkins是一款基于Java的持续集成工具. 2.准备工具:下载一个jenkins的war包. 3.启动方法:如把jenkins. ...
- R语言中的采样与生成组合
不放回采样:sample(1:10, 5, replace = FALSE) 生成组合:
- API服务网关(Zuul)
技术背景 前面我们通过Ribbon或Feign实现了微服务之间的调用和负载均衡,那我们的各种微服务又要如何提供给外部应用调用呢. 当然,因为是REST API接口,外部客户端直接调用各个微服务是没有问 ...
- 公司最近把开发人员的系统全部改为windows了
公司最近把开发人员的开发环境全部改为windows了,唯一linux系统(一位做python 开发的同事自己安装的),被要求下午下班前改为windows 系统,windows 是公认的不适合开发,我家 ...
- unity3D 中的C#脚本一个类调用另一类中简单方法
案例展示 SubMenuManage类中的实例化代码如下: static SubMenuManage sub_this; public static SubMenuManage Instance() ...
- 笨办法06字符串(string)和文本
代码如下: # coding : utf-8 x = "There are %d types of people." % 10 binary = "binary" ...
- [BZOJ1269]文本编辑器editor
Problem 有n个操作 Solution splay模板题,用splay维护下标. Notice 需要把l的前一个位置旋转到根,r的后一个位置旋转到根的右节点.所以特别要注意0的大坑. Code ...
- 升级pip10.0.0后出现ModuleNotFoundError: No module named 'pip'的问题
pip10升级后各种pip install出错----- Traceback (most recent call last): File "/usr/local/bin/pip", ...
- Matlab中小语法点总结(更新中)
1. A(:,1)' A(:)' A(:).' A(:,n)' 对矩阵A的低n列进行共轭转置:A(:).'对矩阵A进行转置: 2.subplot的使用方法: h =subplot(m,n,p) ...
- JavaWeb基础-Jsp基础语法
jsp基础语法 JSP的组成 静态内容.指令.表达式.小脚本.声明.注释 JSP的生命周期 用户发出index.jsp ,服务端判断是否是第一次请求,若是第一次请求,则tomcat中的JSP引擎中的文 ...