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 题意:给你一个序列,你可以交换相邻的两个数,要达到一个要求,所有相同的数都相邻,问你交换次数最少是多少 思路 ...
随机推荐
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 表格:表示一个警告的操作
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 简述javascript的解析与执行
我们知道浏览器中javascript程序的执行是基于变量与函数的.那么浏览器是如何保存数据,又是如何执行的呢?今天我们一起来探究一下! 0.写在前 最新的 ECMAScript 标准定义了 8 种数据 ...
- Python学习第九课——匿名函数
匿名函数 # 匿名函数 func = lambda x: x + 1 # x表示参数 x+1表示处理逻辑 print(func(10)) # 输出结果为11 # 例:如何将name="han ...
- 第3节 storm高级应用:6、定时器任务;7、与jdbc的整合使用;8、与jdbc整合打包集群运行
======================================= 5.storm的定时器以及与mysql的整合使用 功能需求:实现每五秒钟打印出当前时间,并将发送出来的数据存入到mysq ...
- 将varchar2类型字段改成clob类型
--增加临时新字段alter table base_temp add temp clob; --将需要改成大字段的项内容copy到大字段中update base_temp set temp=con ...
- eclipse Spring环境搭建 spring tool suite
1.期初用intellij社区版,发现收费版才能开发Java EE. 2.使用eclipse按照网上的教程,在help->eclipse marketplace中搜索sts安装spring工具套 ...
- is application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem
最近试着了解 c++,接触到了QT,写了一个测试程序,在开发环境下正常后移到非开发环境,报错 网上找资料说是少了platforms文件夹中的dll,把里面所有的dll复制到执行程序目录,还是提示,继续 ...
- windows制作动态链接库和使用二
动态库的另一种制作方法: 不使用_declspec(dllexport)关键字,使用.def文件 //exportFun.def 文件名随意 EXPORT add @ //格式 函数名 @编号 < ...
- mac安装扩展出现grep: /usr/include/php/main/php.h
在Mac下执行 sudo phpize时提示: grep: /usr/include/php/main/php.h: No such file or directorygrep: /usr/inclu ...
- mongdb 4.x admin密码忘记,如何 重建admin用户
在mongo db中,或mongo db cluser中,如果admin密码忘记了,必须按下面的步骤来做.思路为注释掉security认证部分,重启mongo server, 重建admin用户,再打 ...