Codeforces Round #373 (Div. 2)A B
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的更多相关文章
- Codeforces Round #373 (Div. 1)
Codeforces Round #373 (Div. 1) A. Efim and Strange Grade 题意 给一个长为\(n(n \le 2 \times 10^5)\)的小数,每次可以选 ...
- 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 ...
- 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 ...
- Codeforces Round #373 (Div. 2)
A,B,C傻逼题,就不说了. E题: #include <iostream> #include <cstdio> #include <cstring> #inclu ...
- 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 ...
- 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 ...
- Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题
B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...
- 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 ...
- 线段树+矩阵快速幂 Codeforces Round #373 (Div. 2) E
http://codeforces.com/contest/719/problem/E 题目大意:给你一串数组a,a[i]表示第i个斐波那契数列,有如下操作 ①对[l,r]区间+一个val ②求出[l ...
随机推荐
- SUID,SGID,Sticky Bit详解(转)
SUID属性 passwd命令可以用于更改用户的密码,一般用户可以使用这个命令修改自己的密码.但是保存用户密码的/etc/shadow文件的权限是400,也就是说只有文件的所有者root用户可以写入, ...
- springMVC源码学习之:springMVC响应请求的几种方法
spring mvc 支持如下的返回方式:ModelAndView, Model, ModelMap, Map,View, String, void. ModelAndView @RequestMap ...
- freeswitch 接通后再录音
需求 录音时不要将前置媒体录制进去. 用法 <action application="set" data="media_bug_answer_req=true&qu ...
- treap树及相关算法
#include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <string ...
- Linux dbg debugging
http://h41379.www4.hpe.com/doc/84final/4538/4538pro_contents.html https://kgdb.wiki.kernel.org/index ...
- Heap Only Tuples (HOT)
Introduction ------------ The Heap Only Tuple (HOT) feature eliminates redundant index entries and a ...
- js中退出语句break,continue和return 比较
js中退出语句break,continue和return 比较 在 break,continue和return 三个关键字中, break,continue是一起的,return 是函数返回语句,但是 ...
- 20150826运算符,if语句
运算符+ - * / % 加减乘除与注意:1.做除法运算时,如果两个操作数同为整数,则运算结果也是整数,不会出现小数.2.上面这些运算,如果两个操作数不同是一个类型,在运算的时候会自动进行类型转换. ...
- 转载:scikit-learn学习之SVM算法
转载,http://blog.csdn.net/gamer_gyt 目录(?)[+] ========================================================= ...
- Why doesn't Genymotion run on Windows 10?
To date, VirtualBox is not yet fully compatible with Windows 10. As Genymotion relies on the use of ...