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. ..c++中用c语言的输入法

    题目: 竞选时,要求选民在n个候选人中选择,n个人的名字为 A,B,C,D--连续n个大写字母,如果选择n个人名字之外的人员,则为废票.   统计时以输入'#'为结束标记.请按候选人的得票数目从大到小 ...

  2. 用vi写一个C 程序

    root@IdeaPad:~# ls 1.txt 3.txt 5.txt 6.py evilxr test 2.txt 4.txt 5.txt~ e.txt evilxr.txt root@IdeaP ...

  3. 类的扩展--类目和延展--ios

    person+money.h  这是类目类 #import "Person.h" //这是扩展person类的接口类,独立一个文件 @interface Person (Money ...

  4. A quest for the full InnoDB status

    When running InnoDB you are able to dig into the engine internals, look at various gauges and counte ...

  5. 虚拟化之vmware虚拟机扩容与克隆

    前提条件: 1.在新建虚拟机的时候创建磁盘如下图,之后这个磁盘就可以在虚拟机关机状态下动态扩展大小,否则只能通过添加另外一块硬盘的方式来扩容.

  6. HTTP请求方法对照表

    根据HTTP标准,HTTP请求可以使用多种请求方法. HTTP1.0定义了三种请求方法: GET, POST 和 HEAD方法. HTTP1.1新增了五种请求方法:OPTIONS, PUT, DELE ...

  7. SQL SERVER 复制相关存储过程

    适用于所有类型复制的过程 过程 说明 sp_addscriptexec 向发布的所有订阅服务器发布 Microsoft SQL Server 脚本(.sql 文件). sp_adjustpublish ...

  8. Spark(二): 内存管理

    Spark 作为一个以擅长内存计算为优势的计算引擎,内存管理方案是其非常重要的模块: Spark的内存可以大体归为两类:execution和storage,前者包括shuffles.joins.sor ...

  9. [原]对Linux环境下任务调度一点认识

    我一直以来有一个误解,那就是在终端运行某个程序时,按下Ctrl + D时我误以为就是杀死了这个进程,今天才知道原来不是.比如我利用libevent在Linux环境下写了一个网络监听程序,当启动程序之后 ...

  10. 【jmeter】逻辑控制器

    JMeter中的Logic Controller用于为Test Plan中的节点添加逻辑控制器. JMeter中的Logic Controller分为两类:一类用来控制Test Plan执行过程中节点 ...