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 ...
随机推荐
- photoshop cc 版本安装失败解决办法
好久没有碰ps,看了下在ps版本都到cc了.忍不住也想尝试最新版本,但是安装出现了很多问题,导致我花了很多时间才搞定,现在分享给大家几点经验吧. Exit Code: Please see speci ...
- Javascript中null值,特别注意的两点
null 是一个javascript字面量,表示空值,就是没有对象被呈现.他是javascript原始值之一.null值常被放在期望一个对象上,但是不引用任何对象的参数位置,也就是说对象的初始化. 我 ...
- PHP表单
二.PHP表单 1.PHP表单处理 welcome.html <html> <body> <form action="welcome.php" met ...
- js手机站跳转
var yunzhuanhua_pc_domain = "http://www.域名.com#yht"; //PC站网址var yunzhuanhua_wap_domain = & ...
- iOS适配:Masonry介绍与使用实践:快速上手Autolayout
随着iPhone的手机版本越来越多, 那么对于我们广大的开发者来说就是很悲催,之前一直使用代码里面layout的约束来适配, 现在推荐一个第三方Masonry,上手块,操作简单,只能一个字形容他 “爽 ...
- Android 应用层知识纲要
Java基础 * 面向对象 * Java集合框架 * 异常处理 * Java反射, Spring框架,通过反射实现 * 泛型, 静态变成语言 * 文件操作 Android基础 * Activity * ...
- JS 获取各个宽度和高度
IE中: document.body.clientWidth ==> BODY对象宽度 document.body.clientHeight ==> BODY对象高度 document.d ...
- Mvc Controller 单元测试 Mock User.Identity.Name
被测试的Action 包含 User.Identity.Name 代码,在写测试代码需要Mock ControllerContext对象 代码如下: var mock = new Mock<Co ...
- 转:SQL Case when 的使用方法
Case具有两种格式.简单Case函数和Case搜索函数. --简单Case函数 CASE sex WHEN '1' THEN '男' WHEN '2' THEN '女' ELSE '其他' EN ...
- 2661: [BeiJing wc2012]连连看
Description 凡是考智商的题里面总会有这么一种消除游戏.不过现在面对的这关连连看可不是QQ游戏里那种考眼力的游戏.我们的规则是,给出一个闭区间[a,b]中的全部整数,如果其中某两个数x,y( ...