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 ...
随机推荐
- POJ1637 Sightseeing tour (混合图欧拉回路)(网络流)
Sightseeing tour Time Limit: 1000MS Me ...
- kuangbin_ShortPath F (POJ 3259)
判环模板题 有了上一题的经验过得很轻松 除了因为spfa还不是很熟打错了两个字母 然后debug了一小会 #include <iostream> #include <string&g ...
- Java——jdk1.5新特性
/* * 可变参数:--一个方法的参数个数不固定. * 特点: * 只能出现在参数列表的最后. * 调用可变参数的方法时,编译器为该可变参数隐含创建一个数组,在方法体中以数组的形式访问可变参 ...
- Android 初阶自定义 View 字符头像
自己很少做自定义 View ,只有最开始的时候跟着郭神写了一个小 Demo ,后来随着见识的越来越多,特别是在开源社区看到很多优秀的漂亮的控件,都是羡慕的要死,但是拉下来的代码还是看不明白,而且当时因 ...
- vb.net 动态调用api
Imports System Imports System.Runtime.InteropServices Public Class DllInvoke Public Sub New(ByVal DL ...
- 怎么用ABBYY将PDF转换为JPEG图像
FineReader Mac版,全称ABBYY FineReader Pro for Mac,是一款流行的OCR图文识别软件,可快速方便地将扫描纸质文档.PDF文件和数码相机的图像转换成可编辑.可搜索 ...
- 在svg里面画虚线
使用stroke-dasharray="3 2" 属性,其中3和2分别表示画的长度和间隙的长度 比如 <line x1="0" y1="5&q ...
- xunsearch安装配置
1.wget http://www.xunsearch.com/download/xunsearch-full-latest.tar.bz2 2.tar -xjf xunsearch-full-lat ...
- html之texteara
定义多行的文本输入控件,所有浏览器都支持,可容纳无限的文本,等宽的字体. 用css的height和width来设置其框框的大小是个很好的办法,其中的文本换行符为%OD/%OA(回车换行) html5中 ...
- JavaScript:改变li前缀图片和样式
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...