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 ...
随机推荐
- Win10系列:JavaScript 控件的使用
向页面中添加的控件可分为两种类型:标准的HTML控件和WinJS库控件.其中标准的HTML控件是指HTML标准中定义的基本控件,如按钮和复选框:WinJS库控件是为开发基于JavaScript 的Wi ...
- 为什么IT运维工程师要学习Linux系统
不论你是否知道,其实你每天都在使用Linux.每次你访问微博.百度甚至是一些小电影网站,你的客户端(浏览器)都在与运行在Linux系统上的服务端程序进行通讯,大多数的电子设备,例如数位录像机.飞机.自 ...
- unity中键盘WASD控制。(WS控制物体前后移动,AD控制左右旋转。)
private float rotateSpeed = 30f; private float movespeed = 5; void FixedUpdate() { //第一种控制移动 float h ...
- day30-python阶段性复习四
九.函数 函数就是完成特定功能的一个语句组,这组语句可以作为一个单位使用,并且给它取一个名字. 降低编程难度 代码重用 可以通过函数名在程序的不同地方多长执行,这通常叫函数调用(.). 预定义函数 可 ...
- [HDU2475]Box
Problem 先告诉你每个盒子在哪个盒子的内部 接下来有M个操作: 可以把一个盒子及里面的盒子移到另外一个盒子的内部 或者询问你某个盒子最外面的盒子是哪个 Solution 首先可以建成一个图,然后 ...
- find 命令实战巧用
一.命令简介 find 命令的 -size 参数 单位b(不是byte而是block).c.w.k.M.G.默认是单位b ,也就是1block = 512byte = 0.5kb (文件系统ext4) ...
- 7 Serial Configuration 理解(二)
*Serial Configuration Mode 串行配置模式分为:Master Serial 和 Slave Serial (如下图)两类: 两者的区别在与CCLK的输入输出方向:主动模式下为输 ...
- matlab中hold on 和hold off功能的区别
hold off 使但当前轴及图形不具备被刷新的性质 hold on和hold off是相对使用的 前者为,你在当前轴(坐标系)中画了一幅图,再画另一幅是,原来的图还在,与新图共存,都看得到: 后者表 ...
- CodeForces - 779D
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But i ...
- AVD Manager 模拟器使用
一.模拟器配置 1.双击启动AVD Manager,进入配置界面 2.点Create按钮创建 3.配置模拟器基本信息 --AVD Name:设备名称,自己定义一个,用英文(不要用中文) --Devic ...