Codeforces Round #508 (Div. 2)

http://codeforces.com/contest/1038

A

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define IT set<node>::iterator
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 100005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int> pli;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
const double oula=0.57721566490153286060651209;
using namespace std; int a[]; int main(){
std::ios::sync_with_stdio(false);
int n,m;
string str;
cin>>n>>m>>str; for(int i=;i<n;i++){
a[str[i]-'A']++;
}
sort(a,a+);
int ans=0x3f3f3f3f;
int co=;
for(int i=;i>=;i--){ if(a[i]==) break;
ans=min(ans,a[i]);
co++;
}
if(co<m) cout<<;
else cout<<ans*co;
}

B

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define IT set<node>::iterator
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 100005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int> pli;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
const double oula=0.57721566490153286060651209;
using namespace std; int main(){
std::ios::sync_with_stdio(false);
int n;
cin>>n;
if(n==||n==){
cout<<"No"<<endl;
}
else{
cout<<"Yes"<<endl;
if(n&){
cout<<<<" "<<n<<endl;
cout<<n-;
for(int i=;i<n;i++) cout<<" "<<i;
}
else{
cout<<<<" "<<n/<<endl;
cout<<n-;
for(int i=;i<=n;i++){
if(i!=n/) cout<<" "<<i;
}
}
}
}

C

题意:有两个人,每人有n个数字,两个人轮流操作,有两种操作方式:1.去掉对方的一个数字 2.选择自己的一个数字加入自己的分数中

思路:排序后从大到小贪心比较两个人的分数,如果当前是A操作,且分数a[L]>b[R],A就选择操作2,否则选择操作1,B也一样

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define IT set<node>::iterator
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 100005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int> pli;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
const double oula=0.57721566490153286060651209;
using namespace std; int n;
ll a[],b[]; int main(){
std::ios::sync_with_stdio(false);
cin>>n;
for(int i=;i<=n;i++) cin>>a[i];
for(int i=;i<=n;i++) cin>>b[i];
sort(a+,a+n+);
sort(b+,b+n+);
ll ans1=,ans2=;
int L=n,R=n;
while(L&&R){
if(a[L]>b[R]){
ans1+=a[L];
L--;
if(L==){
ans2+=b[R];
R--;
}
else{
if(a[L]>b[R]){
L--;
}
else{
ans2+=b[R];
R--;
}
}
}
else{
R--;
if(R==){
L--;
}
else{
if(b[R]>a[L]){
ans2+=b[R];
R--;
}
else{
L--;
}
}
}
}
//cout<<L<<" "<<R<<endl;
while(L){
ans1+=a[L];
L-=;
}
while(R){
R--;
ans2+=b[R];
R--;
}
cout<<ans1-ans2<<endl;
}

D

题意:有n只动物,每只动物都有一个分数,每次一只动物可以吃掉左边或者右边动物,然后它的分数会减去被吃掉的动物的分数,问最后剩下的动物的分数的最大值是多少

思路:通过模拟可以发现一个规律:如果全是正数,最大值等于数值之和减去最小值的两倍,全是负数,最大值等于数值绝对值之和减去最大值的两倍,混合的情况等于数值的绝对值之和(感觉和今天的蓝桥杯后缀表达式那题思路有点像)

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define IT set<node>::iterator
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 100005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int> pli;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
const double oula=0.57721566490153286060651209;
using namespace std; int n;
ll a[]; int main(){
std::ios::sync_with_stdio(false);
ll sum=;
cin>>n;
ll Min=0x3f3f3f3f,Max=-0x3f3f3f3f;
for(int i=;i<n;i++){
cin>>a[i];
sum+=abs(a[i]);
Min=min(Min,a[i]);
Max=max(Max,a[i]);
}
if(n==) cout<<a[];
else if(n==) cout<<max(a[]-a[],a[]-a[]);
else{
if(Min>) sum-=*Min;
else if(Max<) sum+=*Max;
cout<<sum<<endl;
}
}

E

题意:你有n个砖头,每个砖头都有一个值且两端分别有一种颜色,如果两块砖头接触的端点颜色相同,就可以称这两块砖头为一个序列(你可以将一块砖头翻转),一个序列可能由多块砖头构成,序列的值为所构成的砖头的值之和,求所有情况下所有序列的最大值

思路:设 dp[i][j][x][y]表示用第i个到第j个之间的砖头构成一个序列,序列左端颜色为x,右端颜色为y

有三种情况:

1、使用中间的某些砖头dp[i][j][q][w]=max(dp[i][e][q][r]+dp[e+1][j][r][w])

2、将砖头端点的颜色反转dp[i][j][q][w]=max(dp[i][e][r][w]+dp[e+1][j][q][r])

3、不用中间的一部分砖头dp[i][j][q][w]=max(dp[i][e][q][w],dp[e+1][j][q][w])

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define IT set<node>::iterator
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 100005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int> pli;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
const double oula=0.57721566490153286060651209;
using namespace std; int n;
int dp[][][][]; int main(){
std::ios::sync_with_stdio(false);
cin>>n;
memset(dp,-0x3f3f3f3f,sizeof(dp));
int a,b,c;
for(int i=;i<=n;i++){
cin>>a>>b>>c;
dp[i][i][a][c]=dp[i][i][c][a]=b;
}
int ans=;
for(int i=n;i;i--){
for(int j=i;j<=n;j++){
for(int q=;q<=;q++){
for(int w=;w<=;w++){
for(int e=i;e<=j+;e++){
dp[i][j][q][w]=max(dp[i][j][q][w],max(dp[i][e][q][w],dp[e+][j][q][w]));
for(int r=;r<=;r++){
dp[i][j][q][w]=max(dp[i][j][q][w],max(dp[i][e][r][w]+dp[e+][j][q][r],dp[i][e][q][r]+dp[e+][j][r][w]));
}
}
ans=max(ans,dp[i][j][q][w]);
}
}
}
}
cout<<ans<<endl;
}

Codeforces Round #508 (Div. 2)的更多相关文章

  1. Codeforces Round #508 (Div. 2) E. Maximum Matching(欧拉路径)

     E. Maximum Matching 题目链接:https://codeforces.com/contest/1038/problem/E 题意: 给出n个项链,每条项链左边和右边都有一种颜色(范 ...

  2. Codeforces Round #508 (Div. 2) D. Slime

    D. Slime 题目链接:https://codeforces.com/contest/1038/problem/D 题意: 给出两个数,然后每次可以对相邻的两个数合并,比如x,y,那么合并过后就是 ...

  3. [Codeforces Round #508 (Div. 2)][Codeforces 1038E. Maximum Matching]

    前几天给舍友讲这题的时候感觉挺有意思的,就贴上来吧... 题目链接:1038E - Maximum Matching 题目大意:有\(n\)个棒子,每个条两端有颜色\(c1,c2\)以及他的价值\(v ...

  4. Codeforces Round #508 (Div. 2) C D

    C: C - Gambling 给你两个数列  每一回合A可以选择从第一个序列里面选一个数或者清除第二个序列里面选一个数 同理B能从第二序列里面选数或者清除第一个序列里面一个数 然后 求A所选的数之和 ...

  5. 题解——Codeforces Round #508 (Div. 2) T3 (贪心)

    贪心的选取最优解 然后相减好 记得要开long long #include <cstdio> #include <algorithm> #include <cstring ...

  6. 题解——Codeforces Round #508 (Div. 2) T2 (构造)

    按照题意构造集合即可 注意无解情况的判断 #include <cstdio> #include <algorithm> #include <cstring> #in ...

  7. 题解——Codeforces Round #508 (Div. 2) T1 (模拟)

    依照题意暴力模拟即可A掉 #include <cstdio> #include <algorithm> #include <cstring> #include &l ...

  8. Codeforces 1038F Wrap Around (Codeforces Round #508 (Div. 2) F) 题解

    写在前面 此题数据量居然才出到\(n=40\)???(黑人问号)以下给出一个串长\(|S|=100,n=10^9\)的题解. 题目描述 给一个长度不超过\(m\)的01串S,问有多少个长度不超过\(n ...

  9. Codeforces Round #508 (Div. 2)【A,B,C,D】【实验室日常周赛训练】

    #include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f3f3f #define int long long ...

随机推荐

  1. vs+qt 运行过程出现cannot run rc.exe

    刚开始,我按照网上的一堆教程在qt creator中设置了各种东西,设置完以后,运行时出现cannot run rc.exe,根据百度,将C:\Program Files (x86)\Windows ...

  2. poj 1151 (未完成) 扫描线 线段树 离散化

    #include<iostream> #include<vector> #include<cmath> #include<algorithm> usin ...

  3. python trie

    Trie 库 https://github.com/pytries/marisa-trie/blob/master/docs/tutorial.rst http://marisa-trie.readt ...

  4. PythonStudy——数字类型 Number type

    # 了了解:py2中小整数用int存放,大整数用long# 1.整型 num = -1000000000000000000000000000000000000000000000000 print(nu ...

  5. PythonStudy——汇编语言 Assembly Language

    汇编语言 汇编语言(assembly language)是一种用于电子计算机.微处理器.微控制器或其他可编程器件的低级语言,亦称为符号语言.在汇编语言中,用助记符(Mnemonics)代替机器指令的操 ...

  6. java_免费视频课程汇总

    xml使用场景    各种配置文件    用于用户界面的开发    传输数据:ajax 这个可能过时,因为程序员更喜欢将xml用json来代替    web service:这些老式的web serv ...

  7. python, Image

    PIL: Python Image Library, python平台的图像处理库,要使用Image首先要从PIL库导入Image: from PIL import Image 如果没有安装PIL的包 ...

  8. Batch Close process

    @echo offecho.rem Kill all chrome drivertaskkill /im chromedriver.exe /f pause

  9. 【常用命令】Linux相关命令

    [[TOC]] iostat - 查看系统I/O状况 -k Display statistics in kilobytes per second -m Display statistics in me ...

  10. 3.STM32复位系统

    一.概念 复位: 使系统结束当前运行状态,重新开始运行,并根据复位种类,将系统的寄存器(特定的寄存器除外)恢复到默认状态. 二.复位的种类 1.系统复位 将除了系统后备区域寄存器(BKP)和时钟控制寄 ...