codeforce #129

这篇博客详细解析了CodeForces平台上的两个算法问题:F-Cookies与C.-Statues。对于F-Cookies问题,讨论了如何计算偷取一袋饼干后,剩余饼干数量为偶数的方案数;对于C.-Statues问题,则深入探讨了Anna与Maria在棋盘上移动的游戏策略,以确定谁会赢得游戏。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A

CodeForces 129A

F - Cookies
Time Limit:2000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u

Description

Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even?

Input

The first line contains the only integer n (1 ≤ n ≤ 100) — the number of cookie bags Anna and Maria have. The second line contains n integers ai (1 ≤ ai ≤ 100) — the number of cookies in the i-th bag.

Output

Print in the only line the only number — the sought number of ways. If there are no such ways print 0.

通过观察可以发现,当a[0] + ..a[n-1] 为奇数时,答案为a[i]是偶数的个数,和为偶数时,是a[i]

奇数的个数


/***********************************************
 * Author: fisty
 * Created Time: 2015/6/15 20:53:31
 * File Name   : F.cpp
 *********************************************** */
#include <iostream>
#include <cstring>
#include <deque>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <algorithm>
using namespace std;
#define Debug(x) cout << #x << " " << x <<endl
#define Memset(x, a) memset(x, a, sizeof(x))
const int INF = 0x3f3f3f3f;
typedef long long LL;
typedef pair<int, int> P;
#define FOR(i, a, b) for(int i = a;i < b; i++)
int main() {
    //freopen("in.cpp", "r", stdin);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int sum = 0;
    int odd = 0;
    int even = 0;
    int x;
    FOR(i, 0, n){
        cin >> x;
        if(x % 2) odd++;
        else even++;
        sum += x;
    }
    if(sum % 2) cout << odd << endl;
    else cout << even << endl;
    return 0;
}

C. - Statues

Time Limit:2000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u

Description

In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 × 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone — neither any other statues, nor Anna, nor Maria.

Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is — to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared.

At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner.

Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error.

Input

You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one — for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S".

It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S".

Output

If Maria wins, print string "WIN". If the statues win, print string "LOSE".

Sample Input

Input
.......A
........
........
........
........
........
........
M.......
Output
WIN

搜索是否可以从M到达A, 并且在走的同时有雕塑下落,为可否到达。顺便记录走的时间,如果时间大于8,说明所有雕塑都到达底部,M一定可以到达A,则跳出

/***********************************************
 * Author: fisty
 * Created Time: 2015/6/16 21:10:32
 * File Name   : D.cpp
 *********************************************** */
#include <iostream>
#include <cstring>
#include <deque>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <algorithm>
using namespace std;
#define Debug(x) cout << #x << " " << x <<endl
#define Memset(x, a) memset(x, a, sizeof(x))
const int INF = 0x3f3f3f3f;
typedef long long LL;
typedef pair<int, int> P;
#define FOR(i, a, b) for(int i = a;i < b; i++)
#define MAX_N 10
char G[MAX_N][MAX_N];
int vis[MAX_N][MAX_N][MAX_N];
struct node{
    int x, y, d;
    node(int x, int y, int d):x(x), y(y), d(d){}
};
void bfs(){
    Memset(vis, 0);
    queue<node> que;
    que.push(node(7, 0, 0));
    while(que.size()){
        node q = que.front();
        que.pop();
        if(q.d >= 8){
            cout << "WIN" << endl;
            return ;
        }
        if(G[q.x - q.d][q.y] == 'S') continue;
        for(int i = -1; i <= 1; i++){
            for(int j = -1;j <= 1; j++){
                int x = q.x + i, y = q.y + j;
                if(G[x - q.d][y] != 'S' && x >= 0 && y >= 0 && x < 8 && y < 8){
                    if(!vis[x][y][q.d+1]){
                        que.push(node(x, y, q.d+1));
                        vis[x][y][q.d+1] = 1;
                    }
                }
            }
        }
    }
    puts("LOSE");
}
int main() {
    //freopen("in.cpp", "r", stdin);
    cin.tie(0);
    ios::sync_with_stdio(false);
    FOR(i, 0, 8){
        FOR(j, 0, 8){
            cin >> G[i][j];
        }
    }
    bfs();
    return 0;
}

D String Time Limit:2000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u

Description

One day in the IT lesson Anna and Maria learned about the lexicographic order.

String x is lexicographically less than string y, if either x is a prefix of y (and x ≠ y), or there exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi, and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of the string a. The lexicographic comparison of strings is implemented by operator < in modern programming languages​​.

The teacher gave Anna and Maria homework. She gave them a string of length n. They should write out all substrings of the given string, including the whole initial string, and the equal substrings (for example, one should write out the following substrings from the string "aab": "a", "a", "aa", "ab", "aab", "b"). The resulting strings should be sorted in the lexicographical order. The cunning teacher doesn't want to check all these strings. That's why she said to find only the k-th string from the list. Help Anna and Maria do the homework.

Input

The first line contains a non-empty string that only consists of small Latin letters ("a"-"z"), whose length does not exceed 105. The second line contains the only integer k (1 ≤ k ≤ 105).

Output

Print the string Anna and Maria need — the k-th (in the lexicographical order) substring of the given string. If the total number of substrings is less than k, print a string saying "No such line." (without the quotes).


用优先队列模拟求出字符串中第k大的子串

/***********************************************
 * Author: fisty
 * Created Time: 2015/6/16 19:59:55
 * File Name   : C.cpp
 *********************************************** */
#include <iostream>
#include <cstring>
#include <deque>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <algorithm>
using namespace std;
#define Debug(x) cout << #x << " " << x <<endl
#define Memset(x, a) memset(x, a, sizeof(x))
const int INF = 0x3f3f3f3f;
typedef long long LL;
typedef pair<int, int> P;
#define FOR(i, a, b) for(int i = a;i < b; i++)
#define MAX_N 100100
int k;
string s;
struct node{
    string s;
    int d;
    node(string s = " ", int d = 0) : s(s), d(d){}
    bool operator<(const node &q)const{
        return s > q.s;
    }
};
priority_queue <node> que;
int main() {
    //freopen("in.cpp", "r", stdin);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    cin >> k;
    int n = s.size();
    node t;
    for(int i = 0;i < n; i++){
        t.s = s[i];
        t.d = i;
        que.push(t);
    }
    int ok = 0;
    while(!que.empty()){
        node p = que.top();
        que.pop();
        //cout << p.s << endl;
        k--;
        if(k == 0){
            cout << p.s << endl;
            ok = 1;
            break;
        }
        p.d++;
        if(p.d < s.size()){
            p.s = p.s + s[p.d];
            que.push(p);
        }
    }
    if(!ok) cout << "No such line." << endl;
    return 0;
}






### Codeforces 题目难度分布及评级标准 Codeforces 的题目难度范围广泛,涵盖了从新手到专家级别的各种挑战[^1]。该平台通过细致的分层机制来区分不同难度等级的问题,使得每位参赛者都能找到适合自己水平的任务。 #### 评分体系概述 Codeforces 使用基于积分制的评价系统,其中每道题都有一个对应的分数(rating),用于表示其相对难易程度。较低的 rating 表明这是一道较为简单的题目;而较高的 rating 则意味着更高的复杂性和解决难度。通常情况下: - **简单题**:Rating 小于等于 1200 分 - **中等偏难题**:Rating 范围大约在 1600 至 2000 分之间 - **困难题**:Rating 大于等于 2400 分 这些数值并不是固定的界限,而是根据社区反馈以及比赛实际情况调整的结果。 #### Divisions 和 Contest Types 为了更好地适应不同程度的学习者和技术爱好者的需求,Codeforces 提供了多种类型的竞赛活动,比如 Division 1, Division 2, Division 3 及 Division 4 等不同类型的比赛[^2]。每个 division 对应着不同的最低准入门槛——即参与者应该具备的基础能力或经验水平。例如,在更高级别的比赛中会遇到更多高难度的问题。 #### 技术领域覆盖 平台上发布的题目不仅限于单一的技术方向,还涉及到多个计算机科学的重要分支,如贪心算法、动态规划、图论等领域。这种多样性有助于全面锻炼编程技巧并促进跨学科思维的发展。 ```python # 示例 Python 代码片段展示如何获取某场比赛的信息 import requests def get_contest_info(contest_id): url = f"https://codeforces.com/api/contest.standings?contestId={contest_id}&from=1&count=1" response = requests.get(url).json() if &#39;result&#39; not in response or &#39;problems&#39; not in response[&#39;result&#39;]: return None problems = response[&#39;result&#39;][&#39;problems&#39;] for problem in problems: print(f"{problem[&#39;index&#39;]}: {problem[&#39;name&#39;]} - Rating: {problem.get(&#39;rating&#39;, &#39;N/A&#39;)}") get_contest_info(1669) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值