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 ...
随机推荐
- java笔记3
面向对象的特点: 1.封装: 2.继承 3.多态 好处: 是一种符合人们思考习惯的思想 可以将复杂的事情简单化 将程序员从执行者变为指挥者 二 类与对象 成员变量与局部变量的区别: ...
- [HAOI2008]硬币购物-题解
传送门 解答 根据容斥原理 \[ \left|\bigcap_{i=1}^n \overline{S_i}\right| = |U| - \left|\bigcup_{i=1}^n S_i\right ...
- pyenv基本使用
pyenv使用 1.安装: git clone https://github.com/pyenv/pyenv.git 2.配置pyenv环境变量 echo 'export PYENV_ROOT=&qu ...
- [LOJ2537] [PKUWC2018] Minimax
题目链接 LOJ:https://loj.ac/problem/2537 洛谷:https://www.luogu.org/problemnew/show/P5298 Solution 不定期诈尸 好 ...
- Atcoder Grand Contest 036 D - Negative Cycle
Atcoder Grand Contest 036 D - Negative Cycle 解题思路 在某些情况下,给一张图加或删一些边要使图合法的题目要考虑到最短路的差分约束系统.这一题看似和最短路没 ...
- SpringBoot 常用配置 静态资源访问配置/内置tomcat虚拟文件映射路径
Springboot 再模板引擎中引入Js等文件,出现服务器拒绝访问的错误,需要配置过滤器 静态资源访问配置 @Configuration @EnableWebMvc public class Sta ...
- asp.net core 一个中小型项目实战的起手式——Swagger配置
交流群:863563315 一.Swagger是什么 Swagger 是一款RESTFUL接口的.基于YAML.JSON语言的文档在线自动生成.代码自动生成的工具. 二.如何在项目中加入Swagger ...
- springboot笔记05——profile多环境配置切换
前言 一个应用程序从开发到上线,往往需要经历几个阶段,例如开发.测试.上线.每个阶段所用到的环境的配置可能都是不一样的,Springboot 应用可以很方便地在各个环境中对配置进行切换.所以,今天主要 ...
- Java 之 JDBCTemplate
Spring JDBC Spring 框架是对 JDBC 的简单封装,提供了一个 JDBCTemplate 对象简化 JDBC 的开发. 步骤: 1.导入 jar 包 2.创建 JDBCTemplat ...
- 导航条按钮的设置UIBarButtonItem
1.目的 2.代码 // 设置导航栏的按钮 UIButton *leftNavBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 35, 35 ...