Codeforces Round #281 (Div. 2)

这场题也不难。

不过自己一直犯逗。 不是题目看错就是数组开小。

A,B,C,D都还挺水的,E其实也挺简单,只不过我当时没想明白。。

C的话, 枚举所有可能的d即可,复杂度是排序的nlogn

D的话, 对于奇数来说,黑方只需要跟白方对称走就一定能赢

偶数的话, 白方往1,2走一步就变成了奇数的情况,然后黑方咋走,白方就对称走就行。所以最后白方一定能赢

E

对于给出的t, a, b

我们先把特判的搞定,

无非是t = 1,a=1的情况

根据b是否等于1来特判

然后其他情况就要看方程了

a0+a1t+a2t^2+...=a

a0+a1a+a2a^2+...=b

然后移项得

a1+a2t + a3t^2+...=  (a-a0)/t

a1+a2a + a3a^2+...=(b-a0) /a

会发现这个问题是可以递归解的。

这里a0的值有要求

(a-a0) %t ==0

(b-a0)%a==0

也就是说a0%a == b % a,  a0 % t == a % t

然后就发现其实枚举a0的量非常少

对于a0%a == b%a有a0= k * a + b %a0

a0 <= b && a0 <= a

会发现k=0或者1,而且必须满足a0 % t == a % t

然后接下来就是递归了。就得出答案了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <map>
#define MAXN 55555
#define MAXM 222222
#define INF 1000000001
using namespace std;
int gao(long long a, long long b, long long c, long long d) {
    if(b == 0 && d == 0) return 1;
    if(b == 0 || d == 0) return 0;
    long long ans = 0;
    for(long long i = 0; i <= 1; i++) {
        long long a0 = i * c + d % c;
        if(a0 > b || a0 > d) break;
        if((b - a0) % a == 0) {
            ans += gao(a, (b - a0) / a, c, (d - a0) / c);
        }
    }
    return ans;
}
int main() {
    long long t, a, b;
    scanf("%I64d%I64d%I64d", &t, &a, &b);
    if(t == 1 && a == 1) {
        if(b == 1) {
            puts("inf");
        } else puts("0");
    } else printf("%d\n", gao(t, a, a, b));
    return 0;
}
时间: 2024-09-30 09:35:38

Codeforces Round #281 (Div. 2)的相关文章

Codeforces Round #281 (Div. 2) a

/**  * @brief Codeforces Round #281 (Div. 2) a  * @file a.cpp  * @author 面码  * @created 2014/12/04 17:49  * @edited  2014/12/04 17:58  * @type  implementation  *  */ #include <iostream> #include <fstream> #include <cstdlib> #include <

Codeforces Round #281 (Div. 2) b

/**  * @brief Codeforces Round #281 (Div. 2) b  * @file b.cpp  * @author 面码  * @created 2014/12/04 18:40  * @edited  2014/12/04 18:40  * @type  implementation  *  */ #include <iostream> #include <fstream> #include <cstdlib> #include <

Codeforces Round #281 (Div. 2) d

/**  * @brief Codeforces Round #281 (Div. 2) d  * @file d.cpp  * @author 闈㈢爜  * @created 2014/12/05 18:19  * @edited  2014/12/05 18:19  * @type  game  *  */ #include <iostream> #include <fstream> #include <cstdlib> #include <stack>

Codeforces Round #281 (Div. 2) c

/**  * @brief Codeforces Round #281 (Div. 2) c  * @file c.cpp  * @author 面码  * @created 2014/12/05 11:54  * @edited  2014/12/05 11:54  * @type  brute  *  */ #include <iostream> #include <fstream> #include <cstdlib> #include <stack>

Codeforces Round #281 (Div. 2) A. Vasya and Football 暴力

A. Vasya and Football Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red

Codeforces Round #281 (Div. 2) C. Vasya and Basketball 排序

C. Vasya and Basketball Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from does

Codeforces Round #281 (Div. 2) B. Vasya and Wrestling 水题

B. Vasya and Wrestling Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, th

Codeforces Round #281 (Div. 2) D. Vasya and Chess 博弈

D. Vasya and Chess Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess. The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is

Codeforces Round #281 (Div. 2) 解题报告 A.B.C.D.

A - Vasya and Football 纯模拟..比较坑的是会有不符合足球常识的地方.. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <queue> #inc

Codeforces Round #281 (Div. 2) A. Vasya and Football(模拟)

简单题,却犯了两个错误导致WA了多次. 第一是程序容错性不好,没有考虑到输入数据中可能给实际已经罚下场的人再来牌,这种情况在system测试数据里是有的... 二是chronologically这个词没注意,其实如果输入是按时间顺序的,就直接在线处理就行了,用不着int team1[110][110],team2[110][110]两个数组. #include<iostream> #include<cstdio> #include<cstdlib> #include&l