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,而不知道是那边比較多,所以有四种情况,推断四种情况即可了:

  1. 推断已比赛场数的合法性: 推断已经进行的比赛场数s是否已经超过k了,假设没有超过,推断(k-s)能否被3整除
  2. 推断剩余场数: 推断剩余场数能否把三队胜局填平,假设能够,看扣掉填平后的剩余场数能否被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]的更多相关文章

  1. Codeforces Round #258 (Div. 2) 小结

    A. Game With Sticks (451A) 水题一道,事实上无论你选取哪一个交叉点,结果都是行数列数都减一,那如今就是谁先减到行.列有一个为0,那么谁就赢了.因为Akshat先选,因此假设行 ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  4. Codeforces Round #449 (Div. 2)ABCD

    又掉分了0 0. A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input ...

  5. Codeforces Round #143 (Div. 2) (ABCD 思维场)

    题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...

  6. Codeforces Round #258 (Div. 2) B. Sort the Array

    题目链接:http://codeforces.com/contest/451/problem/B 思路:首先找下降段的个数,假设下降段是大于等于2的,那么就直接输出no,假设下降段的个数为1,那么就把 ...

  7. Codeforces Round #248 (Div. 2) (ABCD解决问题的方法)

    比赛链接:http://codeforces.com/contest/433 A. Kitahara Haruki's Gift time limit per test:1 second memory ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. python - zipfile

    参考:http://www.cnblogs.com/sislcb/archive/2008/11/28/1342822.html zipfile - python处理zip文件的压缩与解压 ZipFi ...

  2. YZOI回忆录&&YZOI3.0介绍&&某些资源的分享

    “那段时光就像块透明的琉璃,美得那么虚幻.飘渺.可是它毕竟在我生命里闪现,哪怕如萤光一样微弱,却照亮了我整个心房.”1.前序伴随着yzoi2.0版本离我而去的是我半年的OI生涯,在这半年内我步入了一个 ...

  3. 五分钟看懂js关键字this

    this是js里面很常用的关键字,而灵活的js也赋予了这个关键字无穷的生命力,相信你也有被它糊弄的时候,我总结了一个6字原则,大部分场合都能清醒分辨this到底指向who,跟大家分享一下,欢迎指正. ...

  4. NPOI使用手册

    HSSFSheet sheet = hssfworkbook.CreateSheet("new sheet"); // Create a row and put some cell ...

  5. ubuntu各版本的区别

    ubuntu.kubuntu以及xubuntu的区别Ubuntu默认是Gnome:KUbuntu用的是KDE,效果比较炫目,但是系统要求也较高XUbuntu用的是Xface,比较轻量,系统要求较低,推 ...

  6. Python 字典 Print 格式化

    __author__ = 'dell' ab = {'Swaroop': 'swaroopch@byteofpython.info', 'Larry': 'larry@wall.org', 'Mats ...

  7. mysql oracle 删除外键约束

    mysql alter table xxx drop foreign key xxx cascade; oracle alter table drop constraint xxxxx cascade ...

  8. 【转】常见 jar包详解

    转载自:http://www.cnblogs.com/xusir/archive/2013/05/19/3086878.html   jar包 用途 axis.jar SOAP引擎包 commons- ...

  9. Unity3d webplayer获取url参数

    Unity3d webplayer获取url参数 1.Unity中代码,在Start方法中调用了HTML的GetUrl方法!Application.ExternalCall( "SayHel ...

  10. 不管,干一个HAPROXY先

    说不定要用到的塞.... 1.wget http://www.haproxy.org/download/1.5/src/haproxy-1.5.12.tar.gz 2.tar -zxvf haprox ...