.

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的更多相关文章

  1. Codeforces Div3 #501 A-E(2) F以后补

    感觉自己有点强迫症  不都写出来就找理由不写题解 http://codeforces.com/contest/1015   题目链接 A. Points in Segments 题目意思  n个线段  ...

  2. CodeForces Round #498 div3

    A: 题目没读, 啥也不会的室友帮我写的. #include<bits/stdc++.h> using namespace std; #define Fopen freopen(" ...

  3. Codeforces Round #535 (Div. 3) [codeforces div3 难度测评]

    hhhh感觉我真的太久没有接触过OI了 大约是前天听到JK他们约着一起刷codeforces,假期里觉得有些颓废的我忽然也心血来潮来看看题目 今天看codeforces才知道居然有div3了,感觉应该 ...

  4. Codeforces Gym 100500F Problem F. Door Lock 二分

    Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/at ...

  5. Codeforces Gym 100002 Problem F "Folding" 区间DP

    Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/ ...

  6. 树形DP ---- Codeforces Global Round 2 F. Niyaz and Small Degrees引发的一场血案

    Aspirations:没有结果,没有成绩,acm是否有意义?它最大的意义就是让我培养快速理解和应用一个个未知知识点的能力. ————————————————————————————————————— ...

  7. Codeforces Round #498 (Div. 3) 简要题解

    [比赛链接] https://codeforces.com/contest/1006 [题解] Problem A. Adjacent Replacements        [算法] 将序列中的所有 ...

  8. codeforces Educational Codeforces Round 24 (A~F)

    题目链接:http://codeforces.com/contest/818 A. Diplomas and Certificates 题解:水题 #include <iostream> ...

  9. 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 ...

随机推荐

  1. ECMAscript5中的map

    今天看到到这样一个问题: ["1", "2", "3"].map(parseInt) 执行结果是什么? 结果是[1,NAN,NAN],很出乎 ...

  2. Ie11 的改变

    摘录地址:     http://www.4fang.net/content.jsp?id=30537 微软在上周刚刚发布了用于Windows 8.1上的首个Internet Explorer 11的 ...

  3. 尚学堂java 参考答案 第七章

    本答案为本人个人编辑,仅供参考,如果读者发现,请私信本人或在下方评论,提醒本人修改 一.选择题 1.ACD 解析:B:java中左边不能直接直接指定长度,和C语言不一样 2.B 3.C 解析:B各行分 ...

  4. log4j的log4j.properties文件配置的详细介绍

    参考(common): http://blog.csdn.net/qq_30175203/article/details/52084127 参考2(log4j.additivity): http:// ...

  5. flask不定参数的传递。多参数,多次传递

    有的时候有一个分类查询,再来一个排序,这就有两个参数要传递多次. 还是不定长度,不定内容的传递. 这个是用request.args来实现: def home(): requests=request.a ...

  6. java套接字(socket)实例

    客户端socket 流程: 1.连接远程主机 2.发送数据 3.接收数据 4.关闭流与socket连接 实例: import java.io.*; import java.net.Socket; im ...

  7. bind配置文件

    options{} - 整个bind使用的全局配置选项 bind监听的端口,数据文件存储位置,缓存的存储位置,权限加密的控制 logging{}- 服务日志选项 日志输出的位置,以及输出的级别 zon ...

  8. Batch Normalization 引出的一系列问题

    Batch Normalization,拆开来看,第一个单词意思是批,出现在梯度下降的概念里,第二个单词意思是标准化,出现在数据预处理的概念里. 我们先来看看这两个概念. 数据预处理 方法很多,后面我 ...

  9. CodeForces ~ 996

    Allen has a LOT of money. He has nn dollars in the bank. For security reasons, he wants to withdraw ...

  10. poj2406(kmp算法)

    Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc&quo ...