ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined)

A. Palindromic Supersequence

You are given a string A. Find a string B, where B is a palindrome and A is a subsequence of B.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, “cotst” is a subsequence of “contest”.
A palindrome is a string that reads the same forward or backward.
The length of string B should be at most 104. It is guaranteed that there always exists such string.
You do not need to find the shortest answer, the only restriction is that the length of string B should not exceed 104.
Input
First line contains a string A (1 ≤ |A| ≤ 103) consisting of lowercase Latin letters, where |A| is a length of A.
Output
Output single line containing B consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string B should not exceed 104. If there are many possible B, print any of them.
Examples
input
aba
output
aba
input
ab
output
aabaa
Note
In the first example, “aba” is a subsequence of “aba” which is a palindrome.
In the second example, “ab” is a subsequence of “aabaa” which is a palindrome.

题意:
给你一个字符串,让你输出一个任意的回文串,输入的字符串是回文串的子串;
分析:
回文串数据范围比较大,直接正着输出一遍输入的字符串+倒着输出一遍;

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;

const int mod = 1e9 + 7;
const int MAXN = 2e3 + 5;
char str[MAXN];

int main() {
    int n;
    scanf("%s", str);
    printf("%s", str);
    for(int i = strlen(str) - 1; i >= 0; --i) {
        printf("%c", str[i]);
    }
    printf("\n");
    return 0;
} 

B. Recursive Queries

Let us define two functions f and g on positive integer numbers.
这里写图片描述
You need to process Q queries. In each query, you will be given three integers l, r and k. You need to print the number of integers x between l and r inclusive, such that g(x) = k.
Input
The first line of the input contains an integer Q (1 ≤ Q ≤ 2 × 105) representing the number of queries.
Q lines follow, each of which contains 3 integers l, r and k (1 ≤ l ≤ r ≤ 106, 1 ≤ k ≤ 9).
Output
For each query, print a single line containing the answer for that query.
Examples
input
4
22 73 9
45 64 6
47 55 7
2 62 4
output
1
4
0
8
input
4
82 94 6
56 67 4
28 59 9
39 74 4
output
3
1
1
5
Note
In the first example:
g(33) = 9 as g(33) = g(3 × 3) = g(9) = 9
g(47) = g(48) = g(60) = g(61) = 6
There are no such integers between 47 and 55.
g(4) = g(14) = g(22) = g(27) = g(39) = g(40) = g(41) = g(58) = 4

题意:
f函数能够消除0(f[601] = f[61]),g(345) = 3 * 4 * 5 = 60 = 6 < 10,给你一个范围和k,问这个范围里g(x)=k的数有多少
分析:
打表+模拟;

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;

const int mod = 1e9 + 7;
const int MAXN = 1e6 + 5;
int dp[10][MAXN], a[MAXN], b[MAXN];
int cnt;

void dfs(int x, int y) {
    if(x == 0) {
        if(y < 10) {
            cnt = y;
            return ;
        }
        dfs(y, 1);
        return ;
    }
    int ans = x % 10;
    x /= 10;
    if(ans == 0) {
        dfs(x, y);
    }
    else dfs(x, ans * y);
}

void init() {
    for(int i = 1; i < MAXN; ++i) {
        dfs(i, 1);
        a[i] = cnt;
    }
    for(int i = 1; i < MAXN; ++i) {
        b[a[i]]++;
        for(int j = 1; j < 10; j++) {
            dp[j][i] = b[j];
        }
        //printf("%d\n", a[i], dp[a[i]][i]);
    }
}

int main() {
    init();
    int n, l, r, k;
    scanf("%d", &n);
    for(int i = 0; i < n; ++i) {
        scanf("%d %d %d", &l, &r, &k);
        printf("%d\n", dp[k][r] - dp[k][l - 1]);
    }
    return 0;
} 

C. Permutation Cycle
题意很难看懂,最后才看懂,差点gg,分值很低。。。
分析:
看懂题过后,就是大暴力。提前暴力的等于A和B的块,在单个的块里环形向右或左移动一步,就可以了;
不要开数组,会RE;

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;

const int mod = 1e9 + 7;
const int MAXN = 1e6 + 5;

int main() {
    int n, a, b;
    scanf("%d %d %d", &n, &a, &b);
    if(a > b) { //注意这个,看不懂题,会一直wa4
        int ans = a;
        a = b;
        b = ans;
    }
    int x = -1;
    for(int i = 0; i < MAXN; ++i) {
        int ans = a * i;
        if(ans > n) break;
        if((n - ans) % b == 0) {
            x = i;
            break;
        }
    }
    if(x < 0) {
        printf("-1\n");
        return 0;
    }
    int cnt = 0;
    for(int i = 1; i <= n; ++i) {
        if(cnt == x) {
            for(int j = i; j < i + b - 1; ++j) {
                printf("%d ", j + 1);
            }
            printf("%d", i);
            i += b - 1;
            if(i != n) printf(" ");
            continue;
        }
        cnt++;
        for(int j = i; j < i + a - 1; ++j) {
            printf("%d ", j + 1);
        }
        printf("%d", i);
        i += a - 1;
        if(i != n) printf(" ");
    }
//  for(int i = 1; i < n + 1; ++i) {
//      if(i != 1) printf(" ");
//      printf("%d", arr[i]);
//  }
    printf("\n");
    return 0;
} 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值