Codeforces Round #508 (Div. 2)
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)的更多相关文章
- Codeforces Round #508 (Div. 2) E. Maximum Matching(欧拉路径)
E. Maximum Matching 题目链接:https://codeforces.com/contest/1038/problem/E 题意: 给出n个项链,每条项链左边和右边都有一种颜色(范 ...
- Codeforces Round #508 (Div. 2) D. Slime
D. Slime 题目链接:https://codeforces.com/contest/1038/problem/D 题意: 给出两个数,然后每次可以对相邻的两个数合并,比如x,y,那么合并过后就是 ...
- [Codeforces Round #508 (Div. 2)][Codeforces 1038E. Maximum Matching]
前几天给舍友讲这题的时候感觉挺有意思的,就贴上来吧... 题目链接:1038E - Maximum Matching 题目大意:有\(n\)个棒子,每个条两端有颜色\(c1,c2\)以及他的价值\(v ...
- Codeforces Round #508 (Div. 2) C D
C: C - Gambling 给你两个数列 每一回合A可以选择从第一个序列里面选一个数或者清除第二个序列里面选一个数 同理B能从第二序列里面选数或者清除第一个序列里面一个数 然后 求A所选的数之和 ...
- 题解——Codeforces Round #508 (Div. 2) T3 (贪心)
贪心的选取最优解 然后相减好 记得要开long long #include <cstdio> #include <algorithm> #include <cstring ...
- 题解——Codeforces Round #508 (Div. 2) T2 (构造)
按照题意构造集合即可 注意无解情况的判断 #include <cstdio> #include <algorithm> #include <cstring> #in ...
- 题解——Codeforces Round #508 (Div. 2) T1 (模拟)
依照题意暴力模拟即可A掉 #include <cstdio> #include <algorithm> #include <cstring> #include &l ...
- Codeforces 1038F Wrap Around (Codeforces Round #508 (Div. 2) F) 题解
写在前面 此题数据量居然才出到\(n=40\)???(黑人问号)以下给出一个串长\(|S|=100,n=10^9\)的题解. 题目描述 给一个长度不超过\(m\)的01串S,问有多少个长度不超过\(n ...
- Codeforces Round #508 (Div. 2)【A,B,C,D】【实验室日常周赛训练】
#include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f3f3f #define int long long ...
随机推荐
- js barcode 打印
新建 html <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset=&quo ...
- C++学习(四十)(C语言部分)之 学生管理系统设计
涉及到的:指针申请内存 结构体数据结构部分排序文件操作 vs2013数据结构 排序 结构体 指针 功能:1.人工录入信息2.删除3.查找4.修改5.全部显示6.文件的读取和保存7.排序 设计:学生信息 ...
- 同一台电脑中同时安装oracle database 服务器端和oracle client 客户端时注意
如果在一台电脑中同时安装oracle的客户端和服务器端软件, 一定要先安装oracle database 服务端,并进行相应的配置 listener.ORA. 然后再去安装oracle client ...
- UEFI+GPT双硬盘安装Win10+Ubuntu16.04双系统
转载请注明出处:http://www.cnblogs.com/willnote/p/6725594.html 安装环境 SSD+HDD双盘,Win10安装在SSD里,HDD分出来60G安装Ubuntu ...
- zombodb 几点说明
内容来自官方文档,截取部分 默认es 索引的副本为0 这个参考可以通过修改索引,或者在创建的时候通过with 参数指定,或者通过pg 的配置文件中指定 索引更多的列以为这使用了更多的es 能力 索引的 ...
- 为什么redis使用单线程还能这么快?
通常来讲,单线程处理能力要比多线程差,但是redis为什么就快了,这主要得益于以下几个原因: 1.纯内存访问,redis将所有数据放在内存中,内存的响应时长大约为100纳秒,这是redis达到每秒万级 ...
- [转]Java反射机制详解
目录 1反射机制是什么 2反射机制能做什么 3反射机制的相关API ·通过一个对象获得完整的包名和类名 ·实例化Class类对象 ·获取一个对象的父类与实现的接口 ·获取某个类中的全部构造函数 - 详 ...
- phpize是什么
安装php(fastcgi模式)的时候,常常有这样一句命令:/usr/local/webserver/php/bin/phpize一.phpize是干嘛的?phpize是什么东西呢?php官方的说明: ...
- 51nod1340 地铁环线
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1340 设x为环线的长度,要判断某个特定的x是否可行,不难将题目转为差分约 ...
- .net 连接 Oracle 可能需要配置
D:\Program Files (x86)\Oracle Developer Tools for VS2013\network\admin\tnsnames.ora