Codeforces Round #373 (Div. 2)

A. Vitya in the Countryside

这回做的好差啊,a想不到被hack的数据,b又没有想到正确的思维 = =

【题目链接】A. Vitya in the Countryside

【题目类型】模拟

&题意:

一个月30天,月亮的大小分别是上面所说的规律,求输入的下一天是变大还是变小

&题解:

我想的是首先n==1的时候,我想的是一定-1,但这样是错的,因为当那一个数是15或0时,那么答案就不是-1了。

最后,只比较最后一个和倒数第二个数就好了,分4种情况。

【时间复杂度】O(n)

&代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define SI(N) scanf("%d",&(N))
#define rep(i,b) for(ll i=0;i<(b);i++)
int n, pre, x;
void Solve() {
while (~SI(n)) {
if (n == 1) {
SI(x);
if (x == 15) puts("DOWN");
else if (x == 0) puts("UP");
else puts("-1");
continue;
}
rep(i, n) {
pre = x;
SI(x);
}
if (pre < x) puts(x == 15 ? "DOWN" : "UP");
else puts(x != 0 ? "DOWN" : "UP");
}
}
int main() {
Solve();
return 0;
}

B. Anatoly and Cockroaches

【题目链接】B. Anatoly and Cockroaches

【题目类型】思维题

&题意:

你要弄出rb交替的字符串,对于每个给出的字符,有2中俄操作:

1、把2个不同的位置交换。

2、把1个位置的染成不同的颜色、

&题解:

标准答案一共2种,r开头和b开头,即s1和s2,就只说s1时,s2同理:

把输入和s1比较,如果不同,要看是r还是b,之后记录不同时他们各个出现的次数,只有不同的位置才需要操作,假设r是6个b是3个,那么一定是3+3,因为要涂3个色,和交换3个。最后取最小值

&代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
#define cle(a,val) memset(a,(val),sizeof(a))
#define SI(N) scanf("%d",&(N))
#define rep(i,b) for(ll i=0;i<(b);i++)
const ll LINF = 0x3f3f3f3f3f3f3f3f;
#define PU(x) puts(#x);
#define PI(A) cout<<(A)<<endl;
const int MAXN = 100000 + 5 ;
char s1[MAXN],s2[MAXN],buf[MAXN];
int n;
void Solve()
{
bool f=0;
rep(i,MAXN)
{
s1[i]=f?'r':'b';
f=!f;
}
f=1;
rep(i,MAXN)
{
s2[i]=f?'r':'b';
f=!f;
}
while(~SI(n)){
scanf("%s",buf);
int u=0,v=0;
int cr=0,cb=0;
rep(i,n)
{
if (s1[i]!=buf[i])
{
s1[i]=='b'?cb++:cr++;
}
}
u=max(cr,cb);
cr=0,cb=0;
rep(i,n)
{
if (s2[i]!=buf[i])
{
s2[i]=='b'?cb++:cr++;
}
}
v=max(cr,cb);
PI(min(u,v))
}
}
int main()
{
Solve();
return 0;
}

Codeforces Round #373 (Div. 2)A B的更多相关文章

  1. Codeforces Round #373 (Div. 1)

    Codeforces Round #373 (Div. 1) A. Efim and Strange Grade 题意 给一个长为\(n(n \le 2 \times 10^5)\)的小数,每次可以选 ...

  2. Codeforces Round #373 (Div. 2) C. Efim and Strange Grade 水题

    C. Efim and Strange Grade 题目连接: http://codeforces.com/contest/719/problem/C Description Efim just re ...

  3. Codeforces Round #373 (Div. 2) C. Efim and Strange Grade —— 贪心 + 字符串处理

    题目链接:http://codeforces.com/problemset/problem/719/C C. Efim and Strange Grade time limit per test 1 ...

  4. Codeforces Round #373 (Div. 2)

    A,B,C傻逼题,就不说了. E题: #include <iostream> #include <cstdio> #include <cstring> #inclu ...

  5. Codeforces Round #373 (Div. 2) A B C 水 贪心 模拟(四舍五入进位)

    A. Vitya in the Countryside time limit per test 1 second memory limit per test 256 megabytes input s ...

  6. Codeforces Round #373 (Div. 2) E. Sasha and Array 线段树维护矩阵

    E. Sasha and Array 题目连接: http://codeforces.com/contest/719/problem/E Description Sasha has an array ...

  7. Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题

    B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...

  8. Codeforces Round #373 (Div. 2) A. Vitya in the Countryside 水题

    A. Vitya in the Countryside 题目连接: http://codeforces.com/contest/719/problem/A Description Every summ ...

  9. 线段树+矩阵快速幂 Codeforces Round #373 (Div. 2) E

    http://codeforces.com/contest/719/problem/E 题目大意:给你一串数组a,a[i]表示第i个斐波那契数列,有如下操作 ①对[l,r]区间+一个val ②求出[l ...

随机推荐

  1. knockoutJs基础1 - 简单的knockoutjs实现

    简单的knockoutjs实现 1.knockoutJs是在MVVM的机制下实现的,所以要有view(HTML页面中的DOM标签)和viewModel(JavaScript中的js代码). 2.在vi ...

  2. STM32的Cortex-M3核与ARM7有何区别?哪个性能更强?

  3. 11g RAC日志体系(cluster,database,asm,scan日志,ADRCI工具的使用)

  4. UML 类图基础知识记录

    UML类图关系(泛化 .继承.实现.依赖.关联.聚合.组合) 依赖(Dependency): 关联(Association): 聚合(Aggregation): 合成(Composition): 泛化 ...

  5. js button onclick动作赋值操作

    昨天遇到的小问题 记录下 主要的东西其实都在这里:http://www.jb51.net/article/35107.htm 我稍微写一下: <script> function show( ...

  6. WAS维护常用操作

    0.WAS学习地址: http://www.open-open.com/doc/list/276?pn=1http://www.doc88.com/p-7498799200332.htmlhttp:/ ...

  7. 如何解决Oracle 11g EM网站报“此网站的安全证书存在问题”

    在IE中输入https://localhost:1158/em 接报错,打不开;提示:“证书错误,此网站安全证书有问题”,解决过程如下: 1.删除与重建dbconsole 2.配置必要的环境变量 1. ...

  8. js 自己创建ready多个可以依次加载

    js会把相同的方法名给覆盖了,很多时候我们都无法再页面加载的时候写多个onload事件,这样只有最后一个才能起效,所以从网上找了找,最后决定自己写一个,例子很简单,希望有高人来指导指导 <!DO ...

  9. javascript 容错

    window.onerror=function(){ return true;} 系统有onerror报错的代码,只要重新一下就可以在javascript错误的时候返回真(true)

  10. sqlite 下载的 ZIP 包的区别

    https://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki sqlite-netFx20-binary-bundle- ...