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 ...
随机推荐
- css 中的grid布局基础
CSS Grid Layout为CSS引入了一个二维网格系统.网格可用于布局主要页面区域或小型用户界面元素. 网格是一组交叉的水平和垂直线 - 一组定义列,其他行.元素可以放在网格上,以行或者列为标准 ...
- OOP ⑴
1.面向对象 类和对象的关系 类是我们在生活中,对身边的一系列事物,进行的不自觉的分类! 只是脑海中的一个印象! 在现实生活中,不存在! 存在的是我们这个印象的具体反映! 对象:用来描述客观事物的一个 ...
- java套接字(socket)实例
客户端socket 流程: 1.连接远程主机 2.发送数据 3.接收数据 4.关闭流与socket连接 实例: import java.io.*; import java.net.Socket; im ...
- HashMap实现原理分析--面试详谈
1. HashMap的数据结构 数据结构中有数组和链表来实现对数据的存储,但这两者基本上是两个极端. 数组 数组存储区间是连续的,占用内存严重,故空间复杂的很大.但数组的二分查找时间复杂度小,为O(1 ...
- bs4 CSS选择器
#https://www.crummy.com/software/BeautifulSoup/bs4/doc/index.zh.html#find-all #beautifulSoup可以解析HTML ...
- linux系统中不同颜色的文件夹及根目录介绍
文件颜色的代表含义: 蓝色:目录 绿色:可执行文件 红色:压缩文件 蓝绿色:链接文件 灰色:其他文件 黄色:设备文件,其中包括block,char,fifo. 白色:表示普通文件 红色闪烁:表示链 ...
- shiro简单学习的简单总结
权限和我有很大渊源. 培训时候的最后一个项目是OA,权限那块却不知如何入手,最后以不是我写的那个模块应付面试. 最开始的是使用session装载用户登录信息,使用简单权限拦截器做到权限控制,利用资源文 ...
- 四川省赛 SCU - 4438
Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text pp. Her j ...
- hdu3001(状压dp,三进制)
Travelling Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Java不同类型字符转换String/int/Float/////
1.int & String int i=5678;String s=""; int->String: s=i+"";或 s=String.val ...