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 题意:给你一个序列,你可以交换相邻的两个数,要达到一个要求,所有相同的数都相邻,问你交换次数最少是多少 思路 ...
随机推荐
- topthink/think-swoole 扩展包的使用 之 Task
本想自己适配的,奈何keng貌似不少,所以果断选择官方提供的包来适配233... 默认条件:thinkphp5.1.*版本下,且安装了swoole扩展 主要演示:task 任务的投递 友情提示:在sw ...
- ROS学习笔记INF-重要操作列表
该笔记将重要操作的步骤进行列表,以便查询: 添加消息 在包中的msg文件夹中创建msg文件 确保package.xml中的如下代码段被启用: <build_depend>message_g ...
- Day9 - A - Apple Catching POJ - 2385
Description 有两棵APP树,编号为1,2.每一秒,这两棵APP树中的其中一棵会掉一个APP.每一秒,你可以选择在当前APP树下接APP,或者迅速移动到另外一棵APP树下接APP(移动时间可 ...
- 如何书写高效的MySQL查询?
How to write efficient MySQL query statements WHERE子句中的书写注意事项 模糊查询(like)时需要注意的事项 索引 字段类型 表连接时的注意事项 其 ...
- 三级联动下拉列表——php 、Ajax
主页面:<!DOCTYPE html><html lang="en"><head> <meta charset="UTF- ...
- ROS-2 : ROS系统层级结构
一.ROS文件系统层级 ROS的文件和文件夹按如下层级来组织:
- iOS大V博客
王巍的博客:王巍目前在日本横滨任职于LINE.工作内容主要进行Unity3D开发,8小时之外经常进行iOS/Mac开发.他的陈列柜中已有多款应用,其中番茄工作法工具非常棒. http://onevca ...
- css的艺术
鲁先生曾经说过:"html和css都不能算一门语言..." html确实不能算一门语言,他只是二三十个英语单词而已,但是css不一样,css是==艺术== 骚操作 上图的12个图标 ...
- Selenium -- ActionChains().move_by_offset() 卡顿的解决方法
测试运行时间 运行时间 发现每次0.5秒,此时需要修改默认的时间 打开Python安装目录下的Lib\site-packages\selenium\webdriver\common\actions\p ...
- 003.CI4框架CodeIgniter, 控制器Controllers的访问地址
01.我们新建一个System文件夹,然后创建一个Login.php类,代码如下: <?php namespace App\Controllers\System; use App\Control ...