Codeforces Round #585 (Div. 2) CF1215A~C
CF1215A. Yellow Cards简单的模拟,给定了黄票张数,判断最少和最多有多少人被罚下场。
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b,aa,bb,n,nnn;
cin>>a>>b>>aa>>bb>>n;
nnn=n;
int t=(aa-)*a+(bb-)*b;
int tt=;
if(aa<=bb)
{
if(n>=aa*a)
{
tt+=a;
n-=aa*a;
}
else
{
tt+=n/aa;
int o=n/aa;
n-=o*aa;
}
if(n>=bb*b)
{
tt+=b;
n-=bb*b;
}
else
{
tt+=n/bb;
int o=n/bb;
n-=o*bb;
}
}
else
{
if(n>=bb*b)
{
tt+=b;
n-=bb*b;
}
else
{
tt+=n/bb;
int o=n/bb;
n-=o*bb;
}
if(n>=aa*a)
{
tt+=a;
n-=aa*a;
}
else
{
tt+=n/aa;
int o=n/aa;
n-=o*aa;
}
}
if(t>=nnn)
{
cout<<"0 "<<tt<<endl;
}
else
{
cout<<min(nnn-t,a+b)<<" "<<tt<<endl;
}
return ;
}
A. Yellow Cards
CF1215B. The Number of Products,我们以第一位数到最后一位数的乘积来分析,1-n的状态数分别是n n-1 n-2……1。
观察易得减少一个正数时,正数的状态-1,减少一个负数时,负数的状态数-1,并正负状态交换,即可O(n)递推求出答案
#include <bits/stdc++.h>
using namespace std;
int a[];
typedef long long ll;
int main()
{
int n;
cin>>n;
ll l=,r=;
ll tt=;
for(int i=;i<=n;++i)
{
ll t;
cin>>t;
if(t>)
{
a[i]=;
}
else
{
a[i]=-;
}
tt*=a[i];
if(tt>)
{
l++;
}
else
{
r++;
}
}
ll al=l,ar=r;
for(int i=;i<=n;++i)
{
if(a[i-]>)
{
l--;
}
else
{
r--;
swap(l,r);
}
al+=l;
ar+=r;
}
cout<<ar<<" "<<al;
return ;
}
B. The Number of Products
CF1215C. Swap Letters 首先只有ab和ba出现的次数为奇数不成立,其余时候ab\ba可和ab\ba一次配对,ab和ba需要两次这里我用了vecotr来避免重复使用
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int>vt1;
vector<int>vt2;
int main()
{
int n,aaa=;
cin>>n;
string str1,str2;
cin>>str1>>str2;
int flag=;
for(int i=;i<str1.size();++i)
{
if(str1[i]=='a'&&str2[i]=='a')
{
flag++;
}
if(str1[i]=='b'&&str2[i]=='b')
{
flag++;
}
}
flag=n-flag;
if(flag%!=)
{
cout<<-;
return ;
}
for(int i=;i<str1.size();++i)
{
if(str1[i]=='a'&&str2[i]=='b')
{
vt1.push_back(i);
}
if(str2[i]=='a'&&str1[i]=='b')
{
vt2.push_back(i);
}
}
for(int i=vt1.size()-;i>=;i-=)
{
int j=i-;
if(j>=)
{
aaa++;
vt1.pop_back();
vt1.pop_back();
}
}
for(int i=vt2.size()-;i>=;i-=)
{
int j=i-;
if(j>=)
{
aaa++;
vt2.pop_back();
vt2.pop_back();
}
}
if(vt1.size())
{
int i=vt1.size()-;
int j=vt2.size()-;
aaa++;
aaa++;
}
cout<<aaa<<endl;
vt1.clear();
vt2.clear();
for(int i=;i<str1.size();++i)
{
if(str1[i]=='a'&&str2[i]=='b')
{
vt1.push_back(i);
}
if(str2[i]=='a'&&str1[i]=='b')
{
vt2.push_back(i);
}
}
for(int i=vt1.size()-;i>=;i-=)
{
int j=i-;
if(j>=)
{
cout<<vt1[j]+<<" "<<vt1[i]+<<endl;
vt1.pop_back();
vt1.pop_back();
}
}
for(int i=vt2.size()-;i>=;i-=)
{
int j=i-;
if(j>=)
{
cout<<vt2[j]+<<" "<<vt2[i]+<<endl;
vt2.pop_back();
vt2.pop_back();
}
}
if(vt1.size())
{
int i=vt1.size()-;
int j=vt2.size()-;
cout<<vt1[i]+<<" "<<vt1[i]+<<endl;
cout<<vt1[i]+<<" "<<vt2[j]+<<endl;
}
return ;
}
C. Swap Letters
Codeforces Round #585 (Div. 2) CF1215A~C的更多相关文章
- Codeforces Round #585 (Div. 2) D. Ticket Game
链接: https://codeforces.com/contest/1215/problem/D 题意: Monocarp and Bicarp live in Berland, where eve ...
- Codeforces Round #585 (Div. 2) C. Swap Letters
链接: https://codeforces.com/contest/1215/problem/C 题意: Monocarp has got two strings s and t having eq ...
- Codeforces Round #585 (Div. 2) B. The Number of Products(DP)
链接: https://codeforces.com/contest/1215/problem/B 题意: You are given a sequence a1,a2,-,an consisting ...
- Codeforces Round #585 (Div. 2) A. Yellow Cards(数学)
链接: https://codeforces.com/contest/1215/problem/A 题意: The final match of the Berland Football Cup ha ...
- Codeforces Round #585 (Div. 2) [补题]
前言 2019.9.16 昨天下午就看了看D题,没有写对,因为要补作业,快点下机了,这周争取把题补完. 2019.9.17 这篇文章或者其他文章难免有错别字不被察觉,请读者还是要根据意思来读,不要纠结 ...
- B. The Number of Products(Codeforces Round #585 (Div. 2))
本题地址: https://codeforces.com/contest/1215/problem/B 本场比赛A题题解:https://www.cnblogs.com/liyexin/p/11535 ...
- A. Yellow Cards ( Codeforces Round #585 (Div. 2) 思维水题
---恢复内容开始--- output standard output The final match of the Berland Football Cup has been held recent ...
- Codeforces Round #585 (Div. 2)
https://www.cnblogs.com/31415926535x/p/11553164.html 感觉很硬核啊这场,,越往后越做不动,,,emmmm,,,(这场是奔着最后一题 2sat 来的, ...
- Codeforces Round #585 (Div. 2) E. Marbles (状压DP)
题目:https://codeforc.es/contest/1215/problem/E 题意:给你一个序列,你可以交换相邻的两个数,要达到一个要求,所有相同的数都相邻,问你交换次数最少是多少 思路 ...
随机推荐
- Spring事务原理分析-部分二
Spring事务原理分析-部分二 说明:这是我在蚂蚁课堂学习了余老师Spring手写框架的课程的一些笔记,部分代码代码会用到余老师的课件代码.这不是广告,是我听了之后觉得很好. 课堂链接:Spring ...
- java学习-初级入门-面向对象④-类与对象-类与对象的定义和使用2
我们继续学习类与对象,上一篇我们定义了 坐标类(Point), 这次我们在Point的基础上,创建一个圆类(Circle). 案例:创建一个圆类 题目要求: 计算圆的周长和面积:求判断两个圆的位置关 ...
- Day10 - 灾难 HYSBZ - 2815
Description 阿米巴是小强的好朋友. 阿米巴和小强在草原上捉蚂蚱.小强突然想,果蚂蚱被他们捉灭绝了,那么吃蚂蚱的小鸟就会饿死,而捕食小鸟的猛禽也会跟着灭绝,从而引发一系列的生态灾难. 学过生 ...
- C# 篇基础知识4——.NET的基础概念
C#语言是与微软的.NET框架紧密地联系在一起的,而.NET框架是微软.NET战略的核心,为了更好的理解C#语言,我们必须了解一些.NET框架的基本知识..NET框架是为开发应用程序推出的一个编程平台 ...
- 网络OSI七层模型及各层作用 与 TCP/IP
背景 虽然说以前学习计算机网络的时候,学过了,但为了更好地学习一些物联网协议(MQTT.CoAP.LWM2M.OPC),需要重新复习一下. OSI七层模型 七层模型,亦称OSI(Open System ...
- alsa-utils 的使用
ref : https://blog.csdn.net/outstanding_yzq/article/details/8126350 一.alsa-utils介绍 ALSA是kernel中的一个声 ...
- linux(centos6.9)下使用yum安装mysql,及启动MySQL等
查看系统自带的mysql版本:rpm -qa | grep mysql 卸载mysql:rpm -e mysql-libs-5.1.73-8.el6_8.x86_64 --nodeps 1. 安装my ...
- vim修改缩进问题
- Eclipse打包Android项目时用到proguard.cfg后,出现的Warning:can't find referenced class问题的解决方案
原文地址:http://blog.csdn.net/u_xtian/article/details/7495023 这个看似简单的问题困扰了我好久了,我已经google了很多相关的信息了,但是在我看来 ...
- 时间戳,秒级,毫秒级转换DateTime格式
解决了本地时间和格林尼治时间差问题 function DateTimeToTp(ConvDate: TDateTime): time_t;var zi: TTimeZoneInformation;be ...