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 题意:给你一个序列,你可以交换相邻的两个数,要达到一个要求,所有相同的数都相邻,问你交换次数最少是多少 思路 ...
随机推荐
- 【转载】C#常用控件属性及方法介绍
C#常用控件属性及方法介绍 目录 1.窗体(Form) 2.Label (标签)控件 3.TextBox(文 ...
- jQuery序列化表单 serialize() serializeArray()(非常重要)
https://m.2cto.com/kf/201412/361303.html 2014-12-15 1.serialize()方法 描述:序列化表单内容为字符串,用于Ajax请求. 格式:var ...
- Android 如何从系统图库中选择图片
转:http://blog.csdn.net/tody_guo/article/details/7560270 这几天我都在做Android的App,同时学习它的API,我将分享一些我学到的东西,比如 ...
- linux零散知识
1.Linux的“| ”管道符用法 上一条命令的输出,作为下一条命令参数 方式:command1 | command2 Linux所提供的管道符“|”将两个命令隔开,管道符左边命令的输出就会作为管道符 ...
- poj2236 Wireless Network(并查集直接套模板
题目地址:http://poj.org/problem?id=2236 题目大意:n台电脑都坏了,只有距离小于d且被修好的电脑才可以互相联系,联系可传递.输入n和d,n个点的坐标x y.两个操作:O ...
- springboot中文官方文档
springboot中文官方文档 https://www.breakyizhan.com/springboot/3028.html spring框架 https://www.breakyizhan.c ...
- C# 创建Windows Service(Windows服务)程序
本文介绍了如何用C#创建.安装.启动.监控.卸载简单的Windows Service 的内容步骤和注意事项. 一.创建一个Windows Service 1)创建Windows Service项目 2 ...
- 设备树DTS 学习:3-常用的DTS 函数
Linux内核中目前DTS相关的函数都是以of_前缀开头的,它们的实现位于内核源码的drivers/of下面 void __iomem*of_iomap(struct device_node *nod ...
- 我的Python学习笔记之文件操作
一,Python的文件类型有两种 1.文本文件 2.二进制文件 文件的操作: 1.打开文件,获取文件的控制权 2.读写文件 3.关闭文件,释放文件的控制权,如果不释放控制权,那么其他程序就不能访问此文 ...
- P1065 单身狗
P1065 单身狗 转跳点: