Educational Codeforces Round 8 ABCDE

套题链接:http://codeforces.com/contest/628

难度类型:前几题比较容易,D题后难度陡增。

A

题解

类型:模拟

根据题意一轮轮做就是了,只是题目有点长,要仔细读。

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
// head
int get(int x) {
    for (int i = 31; ~i; i--) {
        if ((1<return (1<int main() {
    int n, b, p;
    scanf("%d%d%d", &n, &b, &p);
    int ansb = 0, ansp = p * n;
    while (n > 1) {
        int x = get(n);
        ansb += b*x + x/2;
        n = x/2 + n - x;
    }
    printf("%d %d\n", ansb, ansp);
    return 0;
}

B

题解

类型:dp,递推

需要注意是要连续的,然后就是进行一个线性的递推就行了。

dp数组的意义是以某位置为结尾,模4为几的个数。

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
// head
const int N = 3e5+5;
const int mod = 4;

char s[N];
LL dp[2][mod];
int main() {
    gets(s);
    int n = strlen(s);
    int cur = 1, pre = 0;
    LL ans = 0;
    for (int i = 0; i < n; i++) {
        int v = s[i] - '0';
        for (int j = 0; j < mod; j++) {
            dp[cur][j] = 0;
        }
        for (int j = 0; j < mod; j++) {
            int nxt = (j * 10 + v) % mod;
            dp[cur][nxt] += dp[pre][j];
        }
        dp[cur][v%mod]++;
        ans += dp[cur][0];
        swap(cur, pre);
    }
    printf("%I64d\n", ans);
    return 0;
}

C

题解

类型:贪心,模拟

要求变化距离的总和为某数,那尽量多去加,剩下的不变就行了。

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
// head
const int N = 1e5+5;

char s[N];
int main() {
    int n, k;
    scanf("%d%d%s", &n, &k, s);
    for (int i = 0; i < n && k; i++) {
        bool up = abs(s[i] - 'a') < abs(s[i] - 'z');
        int mx = max(abs(s[i] - 'a'), abs(s[i] - 'z'));
        mx = min(mx, k);
        s[i] += up ? mx : -mx;
        k -= mx;
    }
    puts(k ? "-1" : s);
    return 0;
}

D

题解

类型:数位dp

传送门:http://blog.csdn.net/xc19952007/article/details/50720986

E

题解

类型:数据结构,技巧

传送门:http://blog.csdn.net/xc19952007/article/details/50721057

你可能感兴趣的:(套题)