前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >AtCoder Beginner Contest 103

AtCoder Beginner Contest 103

作者头像
attack
发布2018-07-27 15:27:20
2830
发布2018-07-27 15:27:20
举报

刚刚天真的跑去打codechef,才发现那是IOI模拟赛qwq。

atc是比赛还剩40min结束的时候才打的,就做了前三个题

T1

zz模拟

代码语言:javascript
复制
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = 1e5 + 10, INF = 1e9;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int a[5];
int main() {
    a[1] = read(); a[2] = read(); a[3] = read();
    sort(a + 1, a + 4);
    printf("%d", abs(a[2] - a[1]) + abs(a[3] - a[2]));
    return 0;
}

T2

zz模拟

代码语言:javascript
复制
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
const int MAXN = 1e5 + 10, INF = 1e9;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
string a, b;
int main() {
    cin >> a >> b;
    int N = a.length();
    if(N != b.length()) {puts("No"); return 0;}
    //for(int i = 0; i < N; i++) a[i + N] = a[i];
    a = a + a;
    //cout << a << endl << b;
    if(a.find(b) != string::npos) puts("Yes");
    else puts("No");
    return 0;
}

T3

这个就比较厉害了。

首先我们发现,对于每个$a_i$,我们都可以构造一个数使得$x \pmod {a_i} = a_i - 1$

那么输出$\sum_{i = 1}^n a_i - 1$就行了

代码语言:javascript
复制
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
//#define int long long 
using namespace std;
const int MAXN = 1e5 + 10, INF = 1e9;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N;
int a[MAXN], sum = 0;
int check(int val) {
    int ret = 0;
    for(int i = 1; i <= N; i++)
        ret += val % a[i];
    return ret;
}
main() {
    N = read();
    for(int i = 1; i <= N; i++) 
        a[i] = read(), sum += a[i] - 1;
    printf("%d", sum); 
    return 0;
}

T4

首先按照套路按照右端点排序

然后按照从左到右的顺序依次在右端点切就行了

代码语言:javascript
复制
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#define MP(x, y) make_pair(x, y)
#define Pair pair<int, int> 
//#define int long long 
using namespace std;
const int MAXN = 1e6 + 10, INF = 1e9;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N, M;
Pair P[MAXN];
main() {
    N = read(); M = read();
    for(int i = 1; i <= M; i++) {
        int x = read(), y = read();
        P[i] = MP(y, x);
    }
    int ans = 0, last = -1;
    sort(P + 1, P + M + 1);
    for(int i = 1; i <= M;) {
        int j = i + 1;
        while(j <= M && P[i].first == P[j].first) j++;
        if(P[j - 1].second >= last) 
            ans++,          = P[j - 1].first;
        i = j;
    }
    printf("%d\n", ans);
    return 0;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-07-21 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • T1
  • T2
  • T3
  • T4
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档