Codeforces Round #609 (Div. 2) 题解

  • Equation
  • Modulo Equality
  • Long Beautiful Integer
  • Domino for Young
  • K Integers

Equation

\[
Time Limit: 3 s\quad Memory Limit: 256 MB
\]
这题做法很多,甚至可以直接暴力判断

view

#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <cfloat>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#define  lowbit(x)  x & (-x)
#define  mes(a, b)  memset(a, b, sizeof a)
#define  fi         first
#define  se         second
#define  pb         push_back
#define  pii        pair<int, int>

typedef unsigned long long int ull;
typedef long long int ll;
const int    maxn = 1e5 + 10;
const int    maxm = 1e5 + 10;
const ll     mod  = 1e9 + 7;
const ll     INF  = 1e18 + 100;
const int    inf  = 0x3f3f3f3f;
const double pi   = acos(-1.0);
const double eps  = 1e-8;
using namespace std;

int n, m;
int cas, tol, T;

bool ok(int a) {
    for(int i=2; i*i<=a; i++) {
        if(a%i == 0)    return 1;
    }
    return 0;
}

bool che(int a, int b) {
    return ok(a) && ok(b);
}

int main() {
    int d;
    scanf("%d", &d);
    for(int i=1000000000; i>=d; i--) {
        if(che(i, i-d)) return 0*printf("%d %d\n", i, i-d);
    }
    return 0;
}

Modulo Equality

\[
Time Limit: 3 s\quad Memory Limit: 256 MB
\]
首先 \(a[1]\) 一定会变成 \(b\) 中的某个元素,那么就可以枚举 \(a[1]\) 变成了多少,把这个数确定为 \(x\),然后判断合法性并找出所有的 \(x\)。

view

#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <cfloat>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#define  lowbit(x)  x & (-x)
#define  mes(a, b)  memset(a, b, sizeof a)
#define  fi         first
#define  se         second
#define  pb         push_back
#define  pii        pair<int, int>

typedef unsigned long long int ull;
typedef long long int ll;
const int    maxn = 2e3 + 10;
const int    maxm = 1e5 + 10;
const ll     mod  = 1e9 + 7;
const ll     INF  = 1e18 + 100;
const int    inf  = 0x3f3f3f3f;
const double pi   = acos(-1.0);
const double eps  = 1e-8;
using namespace std;

int n, m;
int cas, tol, T;

int a[maxn], b[maxn];
int s[maxn];

int main() {
    scanf("%d%d", &n, &m);
    for(int i=1; i<=n; i++) scanf("%d", &a[i]);
    for(int i=1; i<=n; i++) scanf("%d", &b[i]);
    sort(a+1, a+1+n);
    sort(b+1, b+1+n);
    int ans = inf;
    for(int i=1; i<=n; i++) {
        int d = (b[i]-a[1]+m)%m;
        for(int j=1; j<=n; j++) s[j] = (a[j]+d)%m;
        sort(s+1, s+1+n);
        int f = 1;
        for(int j=1; j<=n; j++) {
            if(s[j] != b[j]) {
                f = 0;
                break;
            }
        }
        if(f)   ans = min(ans, d);
    }
    printf("%d\n", ans);
    return 0;
}

Long Beautiful Integer

\[
Time Limit: 3 s\quad Memory Limit: 256 MB
\]
可以发现最后的数字一定是以 \(k\) 为循环节一直循环的,那么我们就可以考虑一开始给出数字的前 \(k\) 位,看用这 \(k\) 位循环能否更大,如果不能的话,把这 \(k\) 位数字加一,然后在开始循环。

由于用 \(k\) 个 \(9\) 来循环一定是可以的,所以不用担心加一后位数变多的问题。

view

#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <cfloat>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#define  lowbit(x)  x & (-x)
#define  mes(a, b)  memset(a, b, sizeof a)
#define  fi         first
#define  se         second
#define  pb         push_back
#define  pii        pair<int, int>

typedef unsigned long long int ull;
typedef long long int ll;
const int    maxn = 2e5 + 10;
const int    maxm = 1e5 + 10;
const ll     mod  = 1e9 + 7;
const ll     INF  = 1e18 + 100;
const int    inf  = 0x3f3f3f3f;
const double pi   = acos(-1.0);
const double eps  = 1e-8;
using namespace std;

int n, m;
int cas, tol, T;

char s[maxn], s1[maxn], s2[maxn];

bool ok() {
    for(int i=1; i<=n; i++) {
        if(s2[i] > s[i])    return true;
        if(s2[i] < s[i])    return false;
    }
    return true;
}

int main() {
    scanf("%d%d", &n, &m);
    scanf("%s", s+1);
    for(int i=1; i<=m; i++) s1[i] = s[i];
    for(int i=1, j=1; i<=n; i++) {
        s2[i] = s1[j];
        j = j%m+1;
    }
    if(ok()) return 0*printf("%d\n%s\n", n, s2+1);
    for(int i=1; i<=m; i++) s1[i] = s1[i]-'0';
    s1[m]++;
    for(int i=m; i>=1; i--) {
        if(s1[i]>=10) {
            s1[i] -= 10;
            s1[i-1] += 1;
        }
        s1[i] += '0';
    }
    for(int i=1, j=1; i<=n; i++) {
        s2[i] = s1[j];
        j = j%m+1;
    }
    printf("%d\n%s\n", n, s2+1);
    return 0;
}

Domino for Young

\[
Time Limit: 3 s\quad Memory Limit: 256 MB
\]
思维题杀我,但是这题的思路真是太优雅了。

我们把整个图看成一个国际棋盘,国际棋盘是黑白相间的,那么也就是说答案一定是 \(min\) (黑格子,白格子),因为我选了较少的那个,另一个我就一定可以找相邻的凑出来。

view

#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <cfloat>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#define  lowbit(x)  x & (-x)
#define  mes(a, b)  memset(a, b, sizeof a)
#define  fi         first
#define  se         second
#define  pb         push_back
#define  pii        pair<int, int>

typedef unsigned long long int ull;
typedef long long int ll;
const int    maxn = 1e5 + 10;
const int    maxm = 1e5 + 10;
const ll     mod  = 1e9 + 7;
const ll     INF  = 1e18 + 100;
const int    inf  = 0x3f3f3f3f;
const double pi   = acos(-1.0);
const double eps  = 1e-8;
using namespace std;

int n, m;
int cas, tol, T;

int main() {
    scanf("%d", &n);
    ll ans1 = 0, ans2 = 0;
    for(int i=1, x; i<=n; i++) {
        scanf("%d", &x);
        if(i&1) ans1+=x/2, ans2+=(x+1)/2;
        else    ans2+=x/2, ans1+=(x+1)/2;
    }
    printf("%lld\n", min(ans1, ans2));
    return 0;
}

K Integers

\[
Time Limit: 3 s\quad Memory Limit: 256 MB
\]
留坑

原文地址:https://www.cnblogs.com/Jiaaaaaaaqi/p/12080426.html

时间: 2024-08-30 17:11:02

Codeforces Round #609 (Div. 2) 题解的相关文章

Codeforces Round #262 (Div. 2) 题解

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

Codeforces Round #FF (Div. 2) 题解

比赛链接:http://codeforces.com/contest/447 A. DZY Loves Hash time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output DZY has a hash table with p buckets, numbered from 0 to p?-?1. He wants to insert n 

Codeforces Round #259 (Div. 2) 题解

A. Little Pony and Crystal Mine time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n?>?1) is an n?×?n 

Codeforces Round #177 (Div. 2) 题解

[前言]咦?现在怎么流行打CF了?于是当一帮大爷在执着的打div 1的时候,我偷偷的在刷div 2.至于怎么决定场次嘛,一般我报一个数字A,随便再拉一个人选一个数字B.然后开始做第A^B场.如果觉得机密性不高,来点取模吧.然后今天做的这场少有的AK了.(其实模拟赛只做完了4题,最后1题来不及打了) 等等,话说前面几题不用写题解了?算了,让我难得风光一下啦. [A] A. Polo the Penguin and Segments time limit per test 2 seconds mem

Codeforces Round #534 (Div. 2)题解

Codeforces Round #534 (Div. 2)题解 A. Splitting into digits 题目大意 将一个数字分成几部分,几部分求和既是原数,问如何分可以使得分出来的各个数之间的差值尽可能小 解题思路 将n分成n个1相加即可 AC代码 #include<cstring> #include<string> #include<iostream> #include<cstdio> using namespace std; int main

Codeforces Round #561 (Div. 2) 题解

Codeforces Round #561 (Div. 2) 题解 题目链接 A. Silent Classroom 水题. Code #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 105; int n; char s[N], t[N]; int main() { cin >> n; for(int i = 1; i <= n; i++) { scanf(&q

Codeforces Round #608 (Div. 2) 题解

目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 程序 D. Portals 题意 做法 程序 E. Common Number 题意 做法 程序 结束语 Codeforces Round #608 (Div. 2) 题解 前言 题目链接:仅仅只是为了方便以题目作为关键字能查找到我的题解而已(逃 Codeforces 1271A Codeforce

Codeforces Round #617 (Div. 3) 题解

目录 Codeforces Round #617 (Div. 3) 题解 前言 A. Array with Odd Sum 题意 做法 程序 B. Food Buying 题意 做法 程序 C. Yet Another Walking Robot 题意 做法 程序 D. Fight with Monsters 题意 做法 程序 E1. String Coloring (easy version) 题意 做法 程序 E2. String Coloring (hard version) 题意 做法

[Codeforces Round #617 (Div. 3)] 题解 A,B,C,D,E1,E2,F

[Codeforces Round #617 (Div. 3)] 题解 A,B,C,D,E1,E2,F 1296A - Array with Odd Sum 思路: 如果一开始数组的sum和是奇数,那么直接YES, 否则:如果存在一个奇数和一个偶数,答案为YES,否则为NO 代码: int n; int a[maxn]; int main() { //freopen("D:\\code\\text\\input.txt","r",stdin); //freopen(