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 ...
随机推荐
- 微信公众平台开发(免费云BAE+高效优雅的Python+网站开放的API)
虽然校园App是个我认为的绝对的好主意,但最近有个也不错的营销+开发的模式出现:微信平台+固定域名服务器. 微信公众平台的运行模式不外两个: 一.机器人模式或称转发模式,将说话内容转发到服务器上完成, ...
- windows7 jdk 环境变量添加
JAVA_HOME D:\Java;PATH %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;CLASSPATH .;%JAVA_HOME%\lib;%JAVA_HOME%\l ...
- html的input输入框提示信息 点击隐藏
<input type="text" <!-- 文本框 --> name="textfield" value="请输入...& ...
- php定时删除文件夹下文件(清理缓存文件)
<?php ignore_user_abort(); //客户端断开时,可以让脚本继续在后台执行 set_time_limit(0); //忽略php.ini设置的脚本运行时间限制 $inter ...
- TatukGIS-TGIS_ShapeArc.GetPointOnLine
function GetPointOnLine(const _distance: Double; const _offset: Double; const _part: Integer): TGIS_ ...
- 定制linux中的Gtk theme<一>如何设置窗口按钮的多态效果
GTK主题之个人理解: GTK 主题引擎(包含代码所需的图形元素) + 主题配置文件(gtkrc文件)+ 数据资源文件(如图片等) 三者所呈现给用户的视觉风格效果 GTK拥有一套大量的widg ...
- 那些年被我坑过的Python——一夫当关 第十三章(堡垒机初步设计)
堡垒机架构 堡垒机的主要作用权限控制和用户行为审计,堡垒机就像一个城堡的大门,城堡里的所有建筑就是你不同的业务系统 , 每个想进入城堡的人都必须经过城堡大门并经过大门守卫的授权,每个进入城堡的人必 ...
- JS Math.sin() 与 Math.cos() 用法
Math.sin(x) x 的正玄值.返回值在 -1.0 到 1.0 之间: Math.cos(x) x 的余弦值.返回的是 -1.0 到 1.0 之间的数: 这两个函数中的X 都是指 ...
- C语言陷阱——类型转换
以下例子取自<深入理解计算机系统>. 考虑如下的C语言代码: #include<stdio.h> typedef unsigned char* byte_pointer; vo ...
- Obj-C的hello,world 2
https://github.com/facebook/facebook-ios-sdk/blob/master/src/FBAppEvents.h + (void)logEvent:(NSStrin ...