codeforces hello 2020

题目链接:https://codeforces.com/contest/1284

A:New Year and Gaming

题目大意为存在n个字符串S1,S2....Sn和m个字符串t1,t2....tn,对每个年份,需要找到对应的S和对应的t并把它们相连。规则为从第一年开始,对应第一个字符串,后每年都会向后移动一个字符串,当到达最后一个字符串时,下一年会回到第一个字符串。
样例大意为输入n个字符串S1,S2....Sn,之后输入m个字符串t1,t2....tn。然后需要回答q个询问,每个询问为一个整数y代表年份。各个数值范围为n,m(1≤n,m≤20),字符串长度大于1小于10,1≤q≤2020,1≤y≤109

此题我的解法为分别查找两个字符串序列的对应位置,直接%就可以,若为0则转成最后的n或m即可。

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
string ss1[25],ss2[25];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        cin>>ss1[i];
    for(int i=1;i<=m;i++)
        cin>>ss2[i];
    int q;
    scanf("%d",&q);
    while(q--)
    {
        int t;
        scanf("%d",&t);
        int t1=t%n;
        int t2=t%m;
        if(!t1)t1=n;
        if(!t2)t2=m;
        cout<<ss1[t1]<<ss2[t2]<<endl;
    }
    return 0;
}

B:New Year and Ascent Sequence

题目大意为在给出的n个序列中将任意两个组合(不改变顺序,可与自身组合)后存在升序(即为位置靠前的数小于位置靠后的数)。
输入整数n(1≤n≤1e5),接下来的n行都以一个l(1≤l,l表示此序列的长度)开头,后面跟l个数字Si,j(0≤Si,j≤106),所有l的和不能大于1e5。

此题解法为存储每个序列的最大值和最小值,同时判定此序列中是否本身存在升序。后将最小值+1的数量做前缀和,若本身存在升序,则将最小值+1设为0加入前缀和。最后用最大值从前缀和中取就可以。

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
const int maxn=1e6+7;
int minn[maxn],maxx[maxn];
bool ok[maxn];
int mmm[maxn];
int main()
{
    int n;
    ll sum=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int l;
        scanf("%d",&l);
        int a;
        int max1,min1;
        scanf("%d",&max1);
        min1=max1;
        for(int j=2;j<=l;j++)
        {
            scanf("%d",&a);
            if(a<min1)min1=a;
            if(a>min1)ok[i]=1;
            if(a>max1)max1=a;
        }
        maxx[i]=max1;
        minn[i]=min1;
        if(ok[i])mmm[0]++;
        else mmm[min1+1]++;
    }
    for(int i=1;i<maxn;i++)
        mmm[i]+=mmm[i-1];
    for(int i=1;i<=n;i++)
    {
        if(ok[i])sum+=n;
        else{
            sum+=mmm[maxx[i]];
        }
    }
    cout<<sum<<endl;
    return 0;
}

C:New Year and Permutation

此题是找个连续的子序列,让最大值减最小值等于长度减一,可以看出符合的都是在大小连续的子序列中。由此只需要计算排列就行了。

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
const int maxn=250007;
ll fa[maxn];
int main()
{
    int n,mod;
    fa[0]=1;
    scanf("%d%d",&n,&mod);
    for(int i=1;i<=n;i++)fa[i]=fa[i-1]*i%mod;
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        sum+=((n-i+1)*(fa[i]*fa[n-i+1]%mod))%mod;
        sum%=mod;
    }
    cout<<sum<<endl;
}

D没写出来,等考完再补。

原文地址:https://www.cnblogs.com/gxywjl/p/12152217.html

时间: 2024-08-30 18:24:22

codeforces hello 2020的相关文章

Codeforces Hello 2020 选讲

http://codeforces.com/contest/1284/problem/D 把区间对的第二维放入以第一维为下标的数轴中(如1 2 3 4,就把区间[3,4]放入位置1和位置2),如此同个位置的所有区间必须两两相交,即检验第一维相交?第二维相交.同理检验第二维相交?第一维相交.“放入”可用差分的方式.检验:新加入一个区间[x,y],必须满足y>=s_max,且x<=e_min,其中s和e是起点和终点.可用multiset维护加入.检测.删除. 1 #include <bits

Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3

A,有多个线段,求一条最短的线段长度,能过覆盖到所又线段,例如(2,4)和(5,6) 那么我们需要4 5连起来,长度为1,例如(2,10)(3,11),用(3,10) 思路:我们想一下如果题目说的是最长我们肯定是取最小x和最大的y连起来就完事. 但是要求长度最小又得覆盖,那么可以这样想,我们需要把最小的x不断右移到这条线段的y, 最大的左移到x,所以就是最大x-最小y完事 #include <bits/stdc++.h> using namespace std; #define ll long

【cf比赛记录】Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)

比赛传送门 只能说当晚状态不佳吧,有点头疼感冒的症状.也跟脑子没转过来有关系,A题最后一步爆搜没能立即想出来,B题搜索没有用好STL,C题也因为前面两题弄崩了心态,最后,果然掉分了. A:简单数学 B:数学+排序 C:字符串搜索 A // https://codeforces.com/contest/1277/problem/A /* 题意: 给出一个数,求不大于该数的完美整数的个数(完美整数指全是一个数组成的数字,如:111, 333333, 444444, 9, 8888 ...) 分析:

Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1) 题解

A..B略 C 对当前的值排序,再二分答案,然后对于(i%x==0 && i%y==0)放入大的,再放其他的贪心解决即可. #include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> #include<map> #define LL long long #define lson rt<<1 #define rson rt<

Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2)

B2 - TV Subscriptions (Hard Version) 遍历,维护一个set和set<pair<int,int>>即可 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int maxn = 1e6+7; 5 const ll mod = 1e9 + 9; 6 #define afdafafafdafaf y1; 7 int ar[maxn]

Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) C. Messy 构造

C. Messy You are fed up with your messy room, so you decided to clean it up. Your room is a bracket sequence s=s1s2-sn of length n. Each character of this string is either an opening bracket '(' or a closing bracket ')'. In one operation you can choo

Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) B. Box 贪心

B. Box Permutation p is a sequence of integers p=[p1,p2,-,pn], consisting of n distinct (unique) positive integers between 1 and n, inclusive. For example, the following sequences are permutations: [3,4,1,2], [1], [1,2]. The following sequences are n

Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) F2. Wrong Answer on test 233 (Hard Version) dp 数学

F2. Wrong Answer on test 233 (Hard Version) Your program fails again. This time it gets "Wrong answer on test 233" . This is the harder version of the problem. In this version, 1≤n≤2?105. You can hack this problem if you locked it. But you can h

Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) D2. Optimal Subsequences (Hard Version) 数据结构 贪心

D2. Optimal Subsequences (Hard Version) This is the harder version of the problem. In this version, 1≤n,m≤2?105. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems. You are given a seque