Codeforces Round #424 (Div. 2) A-C

A. Unimodal Array

水题

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN     freopen("input.txt","r",stdin);
#define FOUT    freopen("output.txt","w",stdout);
#define INFLL   0x3f3f3f3f3f3f3f
#define lson    l,m,rt<<1
#define rson    m+1,r,rt<<1|1
typedef long long LL;
typedef pair<double, double> PII;

const int maxn = 100 + 5;

int a[maxn];
int b[maxn];

int main() {
    //FIN
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n -1; i++) {
        if(a[i] - a[i + 1] > 0) b[i] = 1;
        else if(a[i] - a[i + 1] == 0) b[i] = 0;
        else if(a[i] - a[i + 1] < 0) b[i] = -1;
    }
    for(int i = 1; i <= n - 2; i++) {
        //cout << b[i]<<"  ";
        if(b[i + 1] < b[i]) {
            cout <<"NO"<<endl;
            return 0;
        }
    }
    cout <<"YES"<<endl;
    return 0;
}

  

B. Keyboard Layouts

比第一题还水...

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN     freopen("input.txt","r",stdin);
#define FOUT    freopen("output.txt","w",stdout);
#define INFLL   0x3f3f3f3f3f3f3f
#define lson    l,m,rt<<1
#define rson    m+1,r,rt<<1|1
typedef long long LL;
typedef pair<double, double> PII;

char s1[30];
char s2[30];
char s3[1005];

int main() {
    //FIN
    cin >> s1;
    cin >> s2;
    cin >> s3;
    int len = strlen(s3);
    for(int i = 0; i < len; i++) {
        int flag = 0;
        if(s3[i] >= ‘0‘ && s3[i] <= ‘9‘) {
            cout << s3[i];
            continue;
        }
        if(s3[i] >= ‘A‘ && s3[i] <= ‘Z‘) {
            flag = 1;
            s3[i] += 32;
        }
        for(int j = 0; j < 26; j++) {
            if(s1[j] == s3[i]) {
                if(flag) printf("%c", s2[j] - 32);
                else cout << s2[j] ;
                break;
            }
        }

    }

    return 0;
}

  

C. Jury Marks

这题看了题解才会做 学会了一个新操作 unique

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN     freopen("input.txt","r",stdin);
#define FOUT    freopen("output.txt","w",stdout);
#define INFLL   0x3f3f3f3f3f3f3f
#define lson    l,m,rt<<1
#define rson    m+1,r,rt<<1|1
typedef long long LL;
typedef pair<double, double> PII;

const int maxn = 2000 + 5;

int a[maxn];
int b[maxn];
int sum[maxn];

vector<int> vec;
map<int, int> mp;

int main() {
    //FIN
    int n, k;
    scanf("%d%d", &k, &n);
    int x;
    for(int i = 1; i <= k; i++) {
        scanf("%d", &a[i]);
        sum[i] += sum[i - 1] + a[i];
    }

    sort(sum + 1, sum + 1 + k);
    int len = unique(sum + 1, sum + 1 + k) - (sum + 1);

    for(int i = 1; i <= n; i++) {
        scanf("%d", &b[i]);
        for(int j = 1; j <= len; j++) {
            int tmp = b[i] - sum[j];
            vec.push_back(tmp);
        }
    }

    sort(vec.begin(), vec.end());

    for(int i = 0; i < vec.size(); i++) {
        mp[vec[i]]++;
    }

    int ans = 0;

    for(int i = 0; i < vec.size(); i++) {
        if(mp[vec[i]] >= n) {
            ans++;
            mp[vec[i]] = 0;
        }
    }
    printf("%d\n", ans);

    return 0;
}

  

时间: 2024-10-13 16:19:41

Codeforces Round #424 (Div. 2) A-C的相关文章

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我

Codeforces Round #424 (Div. 2) E. Cards Sorting(线段树)

题目链接:Codeforces Round #424 (Div. 2) E. Cards Sorting 题意: 将n个数放进一个队列,每次检查队首,看看是不是队列中最小的数,如果是就扔掉,如果不是就放到队尾. 这样直到队列为空,为需要操作多少次. 题解: 考虑用两个指针模拟,最开始now指针指向第一个数,然后nxt指针指向下一个将要被删除的数. 然后我们要算出这里需要移动多少步,然后删掉这个数,一直重复操作,直到将全部的数删完. nxt指针可以用set来维护,now指针可以用并查集来维护. 计

Codeforces Round #424 (Div. 2) D 思维 E set应用,树状数组

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) D. Office Keys 题意:一条直线上,有个办公室坐标 p,有 n个人在a[i],有 k把钥匙在b[i],每个人必须拿到一把钥匙,然后到办公室.问怎么安排花的时间最短. tags:还是不懂套路啊..其实多画两下图就能够感觉出来,2333 关键是要看出来,n个人拿的 n把钥匙应该是连续的. 然后,就是瞎暴力.. #include<bits/stdc++.h> usi

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力

Vladimir wants to modernize partitions in his office. To make the office more comfortable he decided to remove a partition and plant several bamboos in a row. He thinks it would be nice if there are n bamboos in a row, and the i-th from the left is a

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案

There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebo

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)

D题fst了,生无可恋.第二场rated的CF,打得精神恍惚 A. Unimodal Array 题意:判断数列是否是单峰的. 像题意那样分为三个阶段随便判一判就好了 #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> using namespace std; int n,x[105],part=1; bool f=1; int main() { scanf(&quo

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)E. Cards Sorting

题意:有n个数字,我遍历过去,如果他是当前最小值,就删除,否则放到最后面去,问得遍历多少个数字,(直到所有数字消失 思路:我们保存每个数字的位置,这个数字是否能删除,如果他在上一个数字的最后一个位置后面就可以删除了,那么标记下+树状数组(我这里的y表示的就是上一个数删除的最后一个位置) 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N=1e5+10; 5 6 int a[

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Cards Sorting(树状数组)

Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100?0