Codeforces Round #262 (Div. 2) 题解

这篇博客包含了三道编程竞赛题目:第一题关于Vasya的袜子,讨论了Vasya能连续多少天有袜子穿;第二题涉及寻找特定方程的整数解;第三题是关于帮助小海狸用特殊浇水策略最大化花的生长高度。每道题目都提供了输入格式和输出要求。
A. Vasya and Socks
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every m-th day (at days with numbers m, 2m, 3m, ...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks?

Input

The single line contains two integers n and m (1 ≤ n ≤ 100; 2 ≤ m ≤ 100), separated by a space.

Output

Print a single integer — the answer to the problem.

Sample test(s)
input
2 2
output
3
input
9 3
output
13
传送门: 点击打开链接
解题思路:
水题,简单模拟。
代码:
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long lint;
typedef double DB;
//const int MAXN = ;

int main()
{
    int n, m, t = 0;
    scanf("%d%d", &n, &m);
    while(n)
    {
        n--;
        t++;
        if(0 == t%m) n++;
    }
    printf("%d\n", t);
    return 0;
}

B. Little Dima and Equation
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment.

Find all integer solutions x (0 < x < 109) of the equation:

x = b·s(x)a + c, 

where abc are some predetermined constant values and function s(x) determines the sum of all digits in the decimal representation of number x.

The teacher gives this problem to Dima for each lesson. He changes only the parameters of the equation: abc. Dima got sick of getting bad marks and he asks you to help him solve this challenging problem.

Input

The first line contains three space-separated integers: a, b, c (1 ≤ a ≤ 5; 1 ≤ b ≤ 10000;  - 10000 ≤ c ≤ 10000).

Output

Print integer n — the number of the solutions that you've found. Next print n integers in the increasing order — the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109.

Sample test(s)
input
3 2 8
output
3
10 2008 13726 
input
1 2 -18
output
0
input
2 2 -1
output
4
1 31 337 967 

传送门: 点击打开链接
解题思路:
S(X)的取值从1到81,我们可以通过枚举S(x)的值得到x的值,检验是否符合。
代码:
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long lint;
typedef double DB;
const int MAX = 1e9;
const int MAXN = 100;
lint ans[100];

int fun(lint x)
{
    int ret = 0;
    while(x)
    {
        ret += x%10;
        x /= 10;
    }
    return ret;
}

int main()
{
    int a, b, c, n, m = 0;
    scanf("%d%d%d", &a, &b, &c);
    for(int i=1; i<=81; ++i)
    {
        lint x = 1ll*b*pow(i*1.0,a) + 1ll*c;
        if(x<MAX && x>0 && i==fun(x)) ans[m++] = x;
    }
    sort(ans, ans+m);
    printf("%d\n", m);
    for(int i=0; i<m; ++i)
    {
        if(i) printf(" ");
        printf("%I64d", ans[i]);
    }
    printf("\n");
    return 0;
}

C. Present
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on his windowsill and started waiting for them to grow. However, after some time the beaver noticed that the flowers stopped growing. The beaver thinks it is bad manners to present little flowers. So he decided to come up with some solutions.

There are m days left to the birthday. The height of the i-th flower (assume that the flowers in the row are numbered from 1 to n from left to right) is equal to ai at the moment. At each of the remaining m days the beaver can take a special watering and water w contiguous flowers (he can do that only once at a day). At that each watered flower grows by one height unit on that day. The beaver wants the height of the smallest flower be as large as possible in the end. What maximum height of the smallest flower can he get?

Input

The first line contains space-separated integers nm and w (1 ≤ w ≤ n ≤ 105; 1 ≤ m ≤ 105). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Output

Print a single integer — the maximum final height of the smallest flower.

Sample test(s)
input
6 2 3
2 
2 2 2 1 1
output
2
input
2 5 1
5 8
output
9
传送门: 点击打开链接
解题思路:
对所求解的值进行二分。ps:这里的b数组大小是n+w。
代码:
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long lint;
typedef double DB;
const int MAXN = 2e5+10;
const int INF = 2e9;
lint a[MAXN], b[MAXN], ans;
int n, m, w;

bool check(lint k)
{
    memset(b, 0, sizeof(b));
    lint sum = 0, d = 0;
    for(int i=1; i<=n; ++i)
    {
        sum += b[i];
        lint tp = k - a[i] - sum;
        if(tp > 0)
        {
            sum += tp;
            b[i+w] -= tp;
            d += tp;
      //      printf("%I64d %I64d\n", tp, d);
            if(d > m) return false;
        }
    }
    return true;
}

int main()
{
    scanf("%d%d%d", &n, &m, &w);
    for(int i=1; i<=n; ++i)
        scanf("%I64d", a+i);
    lint l = 1, r = 1ll*INF;
    while(l <= r)
    {
        lint mid = (l+r)>>1;
        if(check(mid))
            l = mid + 1, ans = mid;
        else
            r = mid - 1;
    //    printf("%I64d %I64d\n", l, r);
    }
    printf("%I64d\n", ans);
    return 0;
}


### 关于Codeforces Round 704 Div. 2 的信息 对于Codeforces Round 704 Div. 2的比赛,虽然未直接提及具体题目解析或参赛体验的内容,但是可以根据平台的一贯风格推测该轮比赛同样包含了多种算法挑战。通常这类赛事会涉及数据结构、动态规划、图论等方面的知识。 考虑到提供的参考资料并未覆盖到此特定编号的比赛详情[^1],建议访问Codeforces官方网站查询官方题解或是浏览社区论坛获取其他选手分享的经验总结。一般而言,在赛后不久就会有详细的解答发布出来供学习交流之用。 为了帮助理解同类型的竞赛内容,这里提供了一个基于过往相似赛事的例子——如何通过居中子数组特性来解决问题的方法: ```cpp // 假设有一个函数用于处理给定条件下的数组恢复问题 vector<int> restoreArray(vector<vector<int>>& adjacentPairs) { unordered_map<int, vector<int>> adj; for (auto& p : adjacentPairs){ adj[p[0]].push_back(p[1]); adj[p[1]].push_back(p[0]); } int start = 0; for(auto& [num, neighbors] : adj){ if(neighbors.size() == 1){ start = num; break; } } vector<int> res(adjacentPairs.size() + 1); unordered_set<int> seen; function<void(int,int)> dfs = [&](int node, int idx){ seen.insert(node); res[idx] = node; for(auto next : adj[node]){ if(!seen.count(next)){ dfs(next, idx + 1); } } }; dfs(start, 0); return res; } ``` 上述代码展示了利用深度优先搜索(DFS)重建原始序列的一种方式,这与某些情况下解决Codeforces比赛中遇到的问题思路相吻合[^4]。 #### 注意事项 由于缺乏针对Codeforces Round 704 Div. 2的具体材料支持,以上解释更多依赖于对同类活动的理解以及编程技巧的应用实例来进行说明。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值