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

#include<bits/stdc++.h> using namespace std;
#define inf 0x3f3f3f3f3f3f
#define int long long
int vis[];
signed main(){
int n,k;
cin>>n>>k;
string str;
cin>>str;
map<int,int> mp;
int sum=;
for(int i=;i<str.size();i++){
if(!mp[str[i]-'A']){
mp[str[i]-'A']=;
sum++;
}
vis[str[i]-'A']++;
}
if(sum==k){
int ans=inf;
for(int i=;i<k;i++){
ans=min(ans,vis[i]);
}
//cout<<ans<<'\n';
cout<<ans*k;
}else{
cout<<"";
}
return ;
}

思路:猜了一个想法,就过了。
#include<bits/stdc++.h> using namespace std;
#define int long long signed main(){
int n;
cin>>n;
if(n==||n==){
cout<<"No";return ;
}
printf("Yes\n");
int m=n/;
if(n%){
int s1=,s2=;
printf("%lld ",+m);
for(int i=;i<=n;i+=){
printf("%lld ",i);
s1+=i;
}
printf("\n");
printf("%lld ",m);
for(int i=;i<=n;i+=){
printf("%lld ",i);
s2+=i;
}
printf("\n");
// cout<<__gcd(s1,s2)<<'\n';
}else{
int s1=,s2=;
printf("%lld ",m);
for(int i=;i<=n;i+=){
printf("%lld ",i);
s1+=i;
}
printf("\n");
printf("%lld ",m);
for(int i=;i<=n;i+=){
printf("%lld ",i);
s2+=i;
}
printf("\n");
// cout<<__gcd(s1,s2)<<'\n';
}
return ;
}
/* */

思路:贪心+模拟【判断应该加自己和移除对手的值哪一个大。优先队列维护最大值】
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 10050005
priority_queue <int,vector<int>,less<int> >q1;
priority_queue <int,vector<int>,less<int> >q2;
int a[N];
int b[N];
signed main(){
int n;cin>>n;
for(int i=;i<=n;i++){
cin>>a[i];
q1.push(a[i]);
}
for(int i=;i<=n;i++){
cin>>b[i];
q2.push(b[i]);
}
int suma=,sumb=;
int now=;
while(){
now++;
if(q1.empty()&&q2.empty()){
break;
}
int t1=,t2=;
if(now%){//A
if(!q1.empty()&&!q2.empty()){
t1=q1.top();
t2=q2.top();
if(t1>t2){
q1.pop();
suma+=t1;
}else{
q2.pop();
}
}else if(q1.empty()&&!q2.empty()){
q2.pop();
}else if(!q1.empty()&&q2.empty()){
suma+=q1.top();
q1.pop(); } }else{
if(!q1.empty()&&!q2.empty()){
t1=q1.top();
t2=q2.top();
if(t2>t1){
q2.pop();
sumb+=t2;
}else{
q1.pop();
}
}else if(q1.empty()&&!q2.empty()){
sumb+=q2.top();
q2.pop();
}else if(!q1.empty()&&q2.empty()){
q1.pop();
} }
}
//cout<<suma<<" "<<sumb<<'\n';
cout<<suma-sumb;
return ;
}

#include<bits/stdc++.h> using namespace std;
#define int long long
#define inf 1<<30
#define N 10005000
int arr[N];
signed main(){
int n;cin>>n;
if(n==)
{
int qwq;
cin>>qwq;
cout<<qwq<<endl;return ;
}
int flag1=;int flag2=;
int sum1=;int minx=inf;
for(int i=;i<=n;i++) {
cin>>arr[i];
sum1+=abs(arr[i]);
if(arr[i]<){
flag1=;
}else if(arr[i]>){
flag2=;
}
minx=min(minx,abs(arr[i]));
}
if(flag1&&flag2){
cout<<sum1;
}else{
cout<<sum1-abs(minx)*;
}
return ;
}
Codeforces Round #508 (Div. 2)【A,B,C,D】【实验室日常周赛训练】的更多相关文章
- Codeforces Round #508 (Div. 2)
		
Codeforces Round #508 (Div. 2) http://codeforces.com/contest/1038 A #include<bits/stdc++.h> us ...
 - 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 ...
 
随机推荐
- 程序员生存之道,多写bug!
			
1.代码写得好,bug少,看起来就像闲人. 2.注释多,代码清晰,任何人接手非常方便,看起来谁都都可以替代. 3.代码写得烂,每天风风火火改bug,各种救火,解决各种线上重大问题,于是顺理成章为公司亮 ...
 - noip2019集训测试赛(二十一)Problem A: Colorful Balls
			
Problem A: Colorful Balls Description Snuke放了N个一排彩色的球.从左起第i个球的颜色是ci重量是wi她可以通过执行两种操作对这些球重新排序操作1:选择两个相 ...
 - mysql中数据表记录的增删查改(2)
			
select `数据表.字段1`, group_concat(`数据表.字段2`) from `数据表` group by `数据表.字段1` order by `数据表.字段1` desc; sel ...
 - GIT讲解
			
一.什么是Git: Git是目前世界上最先进的分布式版本控制系统. 二.为什么要用版本控制系统: 1.更方便的存储版本 2.恢复之前的版本 3.更方便的进行对比 4.协同合作 三.如何安装GIT: 1 ...
 - 关于Python中的可变对象与不可变对象的区别(转)
			
转自:https://blog.csdn.net/rookinzhang/article/details/80259857 Python中可变对象和不可变对象:https://www.cnblogs. ...
 - Webform中的前后端分离
			
Webform常用的开发方式 (1)运用服务器端控件的aspx页面 (2)一般处理程序+html静态页面+Ajax(所谓的前后端分离) (3)一般处理程序+html模板引擎 这里简单记录html+ ...
 - Java 之 web 相关概念
			
一.软件架构 1.C/S:客户端/服务器端 2.B/S:浏览器/服务器端(目前常用) 二.网络资源 1.静态资源 静态资源:所有用户访问后,得到的结果都是一样的,称为静态资源,静态资源可以直接被浏览器 ...
 - SVN上文件出现左侧黄色箭头右侧绿色箭头的双向箭头
			
转自:https://blog.csdn.net/jiuweihu521/article/details/90902152 与资源库对比又没有要提交的东西,网上说删除这个目录,然后更新整个配置库..我 ...
 - IOS 之 NSBundle 使用
			
来源:http://blog.sina.com.cn/s/blog_b0c59541010151rd.html An NSBundle object represents a location in ...
 - Python2 和 pip2 存在, Python3 也存在,但是 pip3 不存在的解决办法
			
sudo curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py sudo python3 get-pip.py 输入两行命令即可