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. hbase(ERROR: org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet)

    今天启动clouder manager集群时候hbase list出现 (ERROR: org.apache.hadoop.hbase.ipc.ServerNotRunningYetException ...

  2. URAL 1076 Trash Trash(最大权匹配)

    Trash Time limit: 1.0 secondMemory limit: 64 MB You were just hired as CEO of the local junkyard.One ...

  3. js中arguments,caller,callee,apply的用法小结

    <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <style typ ...

  4. android语言适配

    虽然我们现在做的app基本只在国内使用,所以只需要中文,但是我们要把眼光放长远一点,以后我们的APP发展到了国外呢,所以我们就要做语言适配了   很简单 在res目录下,右键  New Resourc ...

  5. C#学习之LinqtoSql类的简单例子

    LinqtoSql类把访问.操作数据库的细节封装了起来,把连接操作数据库变得相当简单.下面是简单的例子. 第一步:添加LinqtoSql类 1.创建一个控制台应用程序项目,下载一个NrothWind ...

  6. CSRF(Cross-site request forgery)跨站请求伪造

    CSRF 背景与介绍 CSRF(Cross Site Request Forgery, 跨站域请求伪造)是一种网络的攻击方式,它在 2007 年曾被列为互联网 20 大安全隐患之一.其他安全隐患,比如 ...

  7. Linux-NTP-Server+Client

    GMT/UTC/CST;/etc/localtime,/usr/share/zoneinfo/*时区文件,/etc/profile加TZ变量;硬件时间RTC,系统时间;date,hwclock,tzs ...

  8. python中保留两位小数

    今天写程序的时候碰到了一个问题关于如何控制浮点数只显示小数点后两位,正常的想法是用round函数,例如 round(a, 2),但是在面对下面的问题时候round就不太好用了 >>> ...

  9. WebLogic11g-半小时让你的domain集群化

    WebLogic11g-半小时让你的domain集群化 WebLogic11g-负载分发 weblogic proxy.war配置 web.xml <!DOCTYPE web-app PUBLI ...

  10. Windows 8.1 系统上用Oracle VM VirtualBox 安装windows 2008 R2 SP1 的虚拟机 出现 Error Code: 0x000000C4

    Windows 8.1 本来可以安装Hyper-v来安装虚拟机,但是我现在需要使用Oracle VM VirtualBox来安装虚拟机, 所以必须先卸载Hyper-v VirtualBox 安装的虚拟 ...