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. goaccess 通过jsonpath 转换为prometheus metrics

    goaccess 是一个不错的日志分析工具,包含了json 数据同时支持基于websocket 的实时数据处理,当然我们可以通过jsonpath 的exporter 转换为支持promethues 的 ...

  2. 一 Struts框架(上)

    Struts2 是基于MVC的WEB框架 经过六年多的发展,Struts1已经成为了一个高度成熟的框架,不管是稳定性还是可靠性都得到了广泛的证明.市场占有率超过20%,拥有丰富的开发人群,几乎已经成为 ...

  3. VS2017 对com组件调用返回错误hresult e_fail

    解决步骤如下: 第一步: 第二步:进入VS2017 安装目录,如下(路径仅供参考) 执行:gacutil -i Microsoft.VisualStudio.Shell.Interop.11.0.dl ...

  4. 对Array.prototype.slice.call()方法的理解

    在看别人代码时,发现有这么个写法:[].slice.call(arguments, 0),这到底是什么意思呢? 1.基础 1)slice() 方法可从已有的数组中返回选定的元素. start:必需.规 ...

  5. jsp中forward与redirect

    一.调用方式 我们知道,在servlet中调用转发.重定向的语句如下: request.getRequestDispatcher("new.jsp").forward(reques ...

  6. <亲测>CentOS中yum安装ffmpeg

    CentOS中yum安装ffmpeg 1.升级系统 sudo yum install epel-release -y sudo yum update -y sudo shutdown -r now 2 ...

  7. Mysql建了索引查询很慢

    遇到一个问题,有几个结构一个的查询,表的索引建的也一样,但是有的查询很快,有的却很慢,需要半分钟以上才能执行完. 查看执行计划,并没有什么区别.找了很久原因才发现是主查询和子查询所涉及的表的字符编码不 ...

  8. SQLServer 清空某个库所有表

    select @n=1 insert #temp(tablename) SELECT distinct sobjects.name FROM sysobjects sobjects WHERE sob ...

  9. Python 爬虫 Vimeo视频下载链接

    python vimeo_d.py https://vimeo.com/228013581 在https://vimeo.com/上看到稀罕的视频 按照上面加上视频的观看地址运行即可获得视频下载链接 ...

  10. SpringBoot 之 MVC

    SpringBoot MVC 和静态资源 首先,我们一定要搞清楚,mvc 配置和 static 配置的联系和区别. mvc 配置其实就是给 spring mvc 框架用的, 具体来说, 比如 @Req ...