Codeforces Round #258 (Div. 2)[ABCD]
Codeforces Round #258 (Div. 2)[ABCD]
ACM
题目地址:Codeforces Round #258 (Div. 2)
A - Game With Sticks
题意:
Akshat and Malvika两人玩一个游戏,横竖n,m根木棒排成#型,每次取走一个交点,交点相关的横竖两条木棒要去掉,Akshat先手,给出n,m问谁赢。
分析:
水题,非常明显无论拿掉哪个点剩下的都是(n-1,m-1),最后状态是(0,x)或(x,0),也就是拿了min(n,m)-1次,推断奇偶就可以。
代码:
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: A.cpp
* Create Date: 2014-07-24 23:32:17
* Descripton:
*/ #include <cstdio>
#include <algorithm>
using namespace std; const int N = 0;
int a, b; int main() {
scanf("%d%d", &a, &b);
if (min(a, b) % 2) {
puts("Akshat");
} else {
puts("Malvika");
}
return 0;
}
B - Sort the Array
题意:
给一个序列,求是否可以通过翻转中间一段数使得整个序列递增,并给翻转区间。
分析:
数为10^5个,所以直接排序,然后找出区间验证就可以。
代码:
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: B.cpp
* Create Date: 2014-07-24 23:49:35
* Descripton:
*/ #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int N = 1e5 + 10; int n, beg, end, flag;
int a[N], b[N];
bool cont; int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
b[i] = a[i];
} sort(b, b + n);
beg = 0;
end = n - 1;
while (beg < n && a[beg] == b[beg])
beg++;
while (end >= 0 && a[end] == b[end])
end--;
if (beg == n) {
printf("yes\n");
printf("1 1\n");
return 0;
}
flag = true;
for (int i = 0; i <= end - beg; i++) {
// cout << b[beg + i] << ' ' << a[end - i] << endl;
if (b[beg + i] != a[end - i]) {
flag = false;
break;
}
}
if (flag) {
printf("yes\n");
printf("%d %d\n", beg + 1, end + 1);
} else {
printf("no\n");
} return 0;
}
C - Predict Outcome of the Game
题意:
三支球队要进行n场足球比赛,已经进行了k场,已知一二两队胜局相差d1,二三两队胜局相差d2,问接下去有没可能出现三队胜局都一样,也就是平局的情况。
分析:
我们仅仅知道是相差d1,d2,而不知道是那边比較多,所以有四种情况,推断四种情况即可了:
- 推断已比赛场数的合法性: 推断已经进行的比赛场数s是否已经超过k了,假设没有超过,推断(k-s)能否被3整除
- 推断剩余场数: 推断剩余场数能否把三队胜局填平,假设能够,看扣掉填平后的剩余场数能否被3整除。
代码:
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: C.cpp
* Create Date: 2014-07-25 00:34:20
* Descripton:
*/ #include <iostream>
using namespace std;
typedef long long ll; ll t, k, n, d1, d2, md; bool jg(ll a, ll b, ll c) {
ll s = a + b + c;
if (k < s || (k - s) % 3)
return 0;
ll t = n - k - (3 * max(max(a, b), c) - s);
if (t < 0 || t % 3)
return 0;
return 1;
} int main() {
cin >> t;
while (t--) {
cin >> n >> k >> d1 >> d2;
md = max(d1, d2);
if (jg(0, d1, d1 + d2) ||
jg(d1 + d2, d2, 0) ||
jg(d1, 0, d2) ||
jg(md - d1, md, md - d2))
cout << "yes" << endl;
else
cout << "no" << endl;
}
return 0;
}
D - Count Good Substrings
题意:
由a和b构成的字符串,假设压缩后变成回文串就是Good字符串。问一个字符串有几个长度为偶数和奇数的Good字串。
分析:
能够发现,无论怎么样,压缩后的字符串是...ababab...
这样的格式的,所以首尾字符同样,那就是Good字符串了。
我们还要证明下随意good字串的首尾字符串都是一样的,这不难。
奇偶问题的话,能够发现随意两个奇数位置上的a及中间的字符组成的字符串都是奇数长度的,同理偶数位置和b。奇数位置上的a和偶数位置上的a的字符串是偶数长度的。
代码:
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: D.cpp
* Create Date: 2014-07-25 10:49:46
* Descripton:
*/ #include <iostream>
#include <string>
#define f(a) (a*(a-1)/2)
using namespace std; string s;
long long r[2][2]; int main() {
cin >> s;
for (int i = 0; s[i]; i++)
r[i&1][s[i]-'a']++;
cout << r[0][0] * r[1][0] + r[0][1] * r[1][1] << ' '
<< f(r[0][0]) + f(r[0][1]) + f(r[1][0]) + f(r[1][1]) + s.length() << endl;
return 0;
}
总结:Orz帆神AK,E题涉及逆元,回头补上~
Codeforces Round #258 (Div. 2)[ABCD]的更多相关文章
- Codeforces Round #258 (Div. 2) 小结
A. Game With Sticks (451A) 水题一道,事实上无论你选取哪一个交叉点,结果都是行数列数都减一,那如今就是谁先减到行.列有一个为0,那么谁就赢了.因为Akshat先选,因此假设行 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
- Codeforces Round #449 (Div. 2)ABCD
又掉分了0 0. A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Codeforces Round #143 (Div. 2) (ABCD 思维场)
题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...
- Codeforces Round #258 (Div. 2) B. Sort the Array
题目链接:http://codeforces.com/contest/451/problem/B 思路:首先找下降段的个数,假设下降段是大于等于2的,那么就直接输出no,假设下降段的个数为1,那么就把 ...
- Codeforces Round #248 (Div. 2) (ABCD解决问题的方法)
比赛链接:http://codeforces.com/contest/433 A. Kitahara Haruki's Gift time limit per test:1 second memory ...
- Codeforces Round #258 (Div. 2) E. Devu and Flowers 容斥
E. Devu and Flowers 题目连接: http://codeforces.com/contest/451/problem/E Description Devu wants to deco ...
- Codeforces Round #258 (Div. 2) D. Count Good Substrings 水题
D. Count Good Substrings 题目连接: http://codeforces.com/contest/451/problem/D Description We call a str ...
随机推荐
- python3 读写excel
一直认为python3可以很快的实现很多简单的功能,今天要读excel表格数据,想来很简单,网上一搜,用xlrd即可,然后很多人给出了不同的版本,号称xlrd3,实际上官网一看,xlrd0.9.4兼容 ...
- call/apply的第一个参数如果为null。this指向window
call/apply是用来改变函数的作用域的,第一次参数为this,第二个参数为传输的值,例如 var a ="windowA"; var b = "windowB&qu ...
- spring 构造注入 异常 Ambiguous constructor argument types - did you specify the correct bean references as constructor arguments
你可能在做项目的时候,需要在项目启动时初始化一个自定义的类,这个类中包含着一个有参的构造方法,这个构造方法中需要传入一些参数. spring提供的这个功能叫“构造注入”, applicationCon ...
- 【开源】前端练手笔记,Chrome扩展应用程序(html+CSS+JS) (1)
项目名称:github-notification 项目地址:https://github.com/WQTeam/github-notification 说明:本人打算抽时间学习前端(html + cs ...
- 省队集训Day3 light
[问题描述] “若是万一琪露诺(俗称 rhl)进行攻击,什么都好,冷静地回答她的问题来吸引她.对方表现出兴趣的话,那就慢慢地反问.在她考虑答案的时候,趁机逃吧.就算是很简单的问题,她一定也答不上来.” ...
- 关于org.openqa.selenium.ElementNotVisibleException
最近在使用Selenium,编写最简单的百度search脚本,结果使用name来定位元素抛出了如下exception: 在定位百度的输入框,使用By.name()定位失败,但是使用By.id()和By ...
- Java Socket Example
1.服务端:server package com.socket; import java.io.BufferedReader; import java.io.IOException; import j ...
- 物联网传输协议MQTT
MQTT是一个物联网传输协议,它被设计用于轻量级的发布/订阅式消息传输,旨在为低带宽和不稳定的网络环境中的物联网设备提供可靠的网络服务.MQTT是专门针对物联网开发的轻量级传输协议.MQTT协议针对低 ...
- Prime Path
poj3126:http://poj.org/problem?id=3126 题意:给你两个数n,k,两个数都是四位数的素数.现在让你改变n的一位数,让n变成另外一个素数.然后把这个素数在改变其中的以 ...
- 微控制器(MCU)架构介绍
微控制器(MicroController)又可简称MCU或μC,也有人称为单芯片微控制器(Single Chip Microcontroller),将ROM.RAM.CPU.I/O集合在同一个芯片中, ...