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的更多相关文章

  1. Codeforces Round #585 (Div. 2) D. Ticket Game

    链接: https://codeforces.com/contest/1215/problem/D 题意: Monocarp and Bicarp live in Berland, where eve ...

  2. 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 ...

  3. 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 ...

  4. Codeforces Round #585 (Div. 2) A. Yellow Cards(数学)

    链接: https://codeforces.com/contest/1215/problem/A 题意: The final match of the Berland Football Cup ha ...

  5. Codeforces Round #585 (Div. 2) [补题]

    前言 2019.9.16 昨天下午就看了看D题,没有写对,因为要补作业,快点下机了,这周争取把题补完. 2019.9.17 这篇文章或者其他文章难免有错别字不被察觉,请读者还是要根据意思来读,不要纠结 ...

  6. 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 ...

  7. A. Yellow Cards ( Codeforces Round #585 (Div. 2) 思维水题

    ---恢复内容开始--- output standard output The final match of the Berland Football Cup has been held recent ...

  8. Codeforces Round #585 (Div. 2)

    https://www.cnblogs.com/31415926535x/p/11553164.html 感觉很硬核啊这场,,越往后越做不动,,,emmmm,,,(这场是奔着最后一题 2sat 来的, ...

  9. Codeforces Round #585 (Div. 2) E. Marbles (状压DP)

    题目:https://codeforc.es/contest/1215/problem/E 题意:给你一个序列,你可以交换相邻的两个数,要达到一个要求,所有相同的数都相邻,问你交换次数最少是多少 思路 ...

随机推荐

  1. 【剑指Offer面试编程题】题目1385:重建二叉树--九度OJ

    题目描述: 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7 ...

  2. 1_03_MSSQL课程_约束详解

    复习: ->创建数据库的SQL:******** create database 数据库名 on ( name=‘’, size=5MB, filegrowth=2MB, filename=&q ...

  3. Spark教程——(6)Spark-shell基于Phoenix访问HBase数据

    package statistics import common.util.timeUtil import org.apache.spark.{SparkConf, SparkContext} imp ...

  4. SystemVerilog基本语法总结(上)

    SystemVerilog基本语法总结(上) 在总结SV的语法之前,先分享一些关于SV的笔试题目,这样更显得具有针对性的总结. a. 验证中,代码覆盖率是指(衡量哪些设计代码在激活触发,而哪一些则一直 ...

  5. acid-事务的原子性、一致性、隔离性、持久性

    博客分类: oracle-dba   原子性  多个事情组成一个单元,要么同时成功或失败,不能只运行其中一个 一致性  事务处理要将数据库从一种状态转变为另一种状态. 一旦提交了修改数据,那么其它人读 ...

  6. AC自动机 (模板)

    AC自动机是用来干什么的: AC自动机是用来解决多模匹配问题,例如有单词s1,s2,s3,s4,s5,s6,问:在文本串ss中有几个单词出现过,类似. AC自动机实现这个功能需要三个部分: 1.将所有 ...

  7. Linux学习《第五章用户文件权限管理》之补充学习

  8. 201705 Ruby基础拾遗

    Mixin override 异常处理 super 与super() 使用%()处理需要string interpolation但同时也需要" "(double quote)的状况 ...

  9. NMEA-0183

    GPGSA( 当前卫星信息)    例:$GPGSA,A,3,01,20,19,13,,,,,,,,,40.4,24.4,32.2*0A    字段0:$GPGSA,语句ID,表明该语句为GPS DO ...

  10. python笔记10

    今日内容 参数 作用域 函数嵌套 知识点回顾 函数基本结果 def func(name,age,email): # 函数体(保持缩进一致) a = 123 print(a) return 1111#函 ...