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 ...
随机推荐
- Linux中的两个经典宏定义:获取结构体成员地址,根据成员地址获得结构体地址;Linux中双向链表的经典实现。
倘若你查看过Linux Kernel的源码,那么你对 offsetof 和 container_of 这两个宏应该不陌生.这两个宏最初是极客写出的,后来在Linux内核中被推广使用. 1. offse ...
- wpf 把两个Bitmap 合并为一个
水平合并 /// <summary> /// 将两个Bitmap水平合并为一个 /// </summary> /// <param name="first&qu ...
- ④ Python3.0字符串
字符串无论是python或者其他语言,是最常用的数据类型之一: 这儿注意在python中可以通过使用引号( ' 或 " )来创建字符串.使用三引号('''或""" ...
- Unity - Profiler参数详解
CPU Usage ● GC Alloc - 记录了游戏运行时代码产生的堆内存分配.这会导致ManagedHeap增大,加速GC的到来.我们要尽可能避免不必要的堆内存分配,同时注意:1 ...
- Jsp页面显示时间:<fmt>标签问题
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%> <%@ taglib ...
- Python_爬虫小实例
爬虫小实例 一.问题描述与分析 Q:查询某一只股票,在百度搜索页面的结果的个数以及搜索结果的变化. 分析: 搜索结果个数如下图: 搜索结果的变化:通过观察可以看到,每个一段时间搜索结果的个数是有所变化 ...
- Jest did not exit one second after the test run has completed.
使用 Jest 进行单元测试时出现如下问题: Jest did not exit one second after the test run has completed. This usually m ...
- js中for循环点击事件(闭包)
<!DOCTYPE html><html lang="en"><head> <meta charset="utf-8" ...
- 如何导出ane所需的swc
来源:http://blog.sina.com.cn/s/blog_6471e1bb01012ard.html 打包.ane文件的时候需要用到ActionScript的扩展库(swc文件),那么如何生 ...
- 学而不思则罔 - SAP云平台ABAP编程环境的由来和适用场景
最近Jerry写了一系列关于SAP云平台ABAP编程环境的技术文章,这些文章都是围绕着在云上的ABAP编程环境的具体知识点来分享,比如要完成一个具体的开发需求,所需要的编程步骤.这些文章陆续收到一些读 ...