EOJ Monthly 2017.12 (暨 ECNU 12 月内部选拔) - A,B,C,G1

这是组队做的一场比赛,也是第一次遇到的全中文的比赛,其中A,G1是最水的题,按题意模拟就行,但是前期忽略了G1,后来才做的,B题是最后A的,D,C也都做了尝试但都没过。
官方题解: EOJ Monthly 2017.12 题解

A. 唐纳德先生和假骰子

Time limit per test: 1.0 seconds

Memory limit: 256 megabytes

在进行某些桌游,例如 UNO 或者麻将的时候,常常会需要随机决定从谁开始。骰子是一种好方案。普通的骰子有六个面,分别是一点、二点、三点、四点、五点、六点,六面向上的概率相同。由于骰子只能产生六种情况,而实际桌游时,却常常有三到四人,所以,我们在掷骰子时,常常采用两颗骰子,这个「随机的选择」就由骰子向上点数之和直接决定。

我们采用这么一种方案,将向上点数之和对  p (人数)取模,模出来的  0,1,,p1  恰好对应  p  个人。但这并不一定是公平的。例如,如果你有算过的话,两枚普通的骰子,在四个人的情形下,就是不公平的。

所以唐纳德先生发明了一种假骰子,这种假骰子也有六个面,但六个面的点数就不再是  1,2,3,4,5,6 ,而是  a1,a2,a3,a4,a5,a6 。如果他精心选择了这六个面的点数,他仍然可以强制公平。

先给出  p  和两枚假骰子六个面的点数,问是否公平。

Input

输入具有如下形式:

pa1 a2 a3 a4 a5 a6b1 b2 b3 b4 b5 b6

第一行一个整数  p  ( 3p4 )。

第二行六个整数,用空格隔开,表示第一枚骰子的点数  a1,a2,a3,a4,a5,a6  ( 1ai6 )。

第三行六个整数,用空格隔开,表示第二枚骰子的点数  b1,b2,b3,b4,b5,b6  ( 1bi6 )。

Output

如果公平输出 YES,否则输出 NO

Examples

input
4
1 2 3 4 5 6
1 2 3 4 5 6
output
NO
input
3
1 2 3 4 5 6
6 5 4 3 2 1
output
YES

代码:

#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<cstring>
#include<map>
using namespace std;
typedef long long ll;
#define M 200000

int p;
int a[10],b[10];
int num[5];

int main()
{
    int i,j;
    scanf("%d",&p);
    for(i=1;i<=6;i++)
        scanf("%d",&a[i]);
    for(i=1;i<=6;i++)
        scanf("%d",&b[i]);

    int sum;
    for(i=1;i<=6;i++)
    {
        for(j=1;j<=6;j++)
        {
            sum=a[i]+b[j];
            sum=sum%p;
            num[sum]++;
        }
    }

    bool flag=true;
    for(i=0;i<=p-1;i++)
    {
        for(j=0;j<=p-1;j++)
        {
            if(num[i]!=num[j])
            {
                flag=false;
                break;
            }
        }
    }
    if(flag)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}

B. 在哈尔滨的寒风中

Time limit per test: 1.0 seconds

Memory limit: 256 megabytes

kblack 来到了寒冬中的哈尔滨,哈尔滨的寒风令 kblack 瑟瑟发抖。

世界上最远的距离,是你与宾馆只差一条冰街,而你却忘了穿上秋裤。

kblack 终于冲进了宾馆,宾馆大厅的地板铺满了五颜六色的地砖,可以被看作是一块  n×m  格的棋盘,为了能使冻僵了的双脚尽快暖和起来,kblack 决定在地砖上走动,但是他被速冻的双脚在棋盘地板上只能走马步。

kblack 居然想知道有多少对地砖(无序点对)他可以通过若干步马步互相抵达!

Input

输入包含一行两个正整数  n m ,表示棋盘的大小,保证  1n×m109  。

Output

输出包含一个整数,表示 kblack 可以通过马步互相到达的无序地砖对数。

Examples

input
1 2
output
0
input
4 2
output
4

当棋盘n×m大于等于3×4时,任意两点均可互相到达,题目变为求从期棋盘中任取两点的组合数,当行数或列数为2时特判

代码:

#include<iostream>
using namespace std;
typedef long long LL;
int main()
{
    LL N, M;
    cin>>N>>M;
    if(N>M)
    {
        int temp=N;
        N=M;
        M=temp;
    }
    if(N<=1)
    {
        cout<<0<<endl;
    }
    else if(N==2)
    {
        LL ans=0;
        LL a=0;
        for(int i=1; i<=2; i++)
        {
            a=(M+2-i)/2;
            //cout<<a<<" ";
            a=a*(a-1);
            if(a>0)
                ans+=a;
        }
        cout<<ans<<endl;
    }
    else if(N==3 && M==3)
    {
        cout<<28<<endl;
    }
    else
    {
        LL ans=N*M;
        cout<<ans*(ans-1)/2<<endl;
    }
    return 0;
}

C. 易位构词

Time limit per test: 2.0 seconds

Memory limit: 256 megabytes

易位构词 (anagram),指将一个单词中的字母重新排列,原单词中的每个字母都出现有且仅有一次。例如 "unce" 可以被易位构词成 "ecnu"。在某些情况下,要求重排而成的依然是一个单词,但本题没有这种要求,因为我们根本没有词典。

我们所感兴趣的是,有些单词中的字母进行适当的重排后,可以使得构成的单词每个对应的位置上字母都不一样。例如 "unce" 和 "ecnu",就有 "u"   "e", "n"   "c", "c"   "n", "e"   "u"。现在给出一个单词,问是否存在这样一个重排。

Input

一行一个单词  s  ( 1|s|105 )。单词完全由  26  个小写英文字母构成。

Output

输出一个单词。如果有多解,输出任意解。如果不存在,输出 impossible

Examples

input
unce
output
ecnu
input
aaaaaa
output
impossible
当出现次数最多的字母出现次数大于总长的一半就是impossible,然后按字母出现次数升序,再按字母降序,然后整体循环右移 (出现最多的字母出现的位数) 那么多位,然后再按下标排回。

代码:
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<cstring>
#include<map>
using namespace std;
typedef long long ll;
#define M 100005

int num[256];
char s[M],ts[M],ans[M];
struct node{  //先按数量升序,再按字母降序
    char c;
    int id;
    bool operator <(const node & obj)const
    {
        return num[c]>num[obj.c]||(num[c]==num[obj.c]&&c<obj.c);
    }
}a[M];

int main()
{
    int i,len;
    scanf("%s",s);
    len=strlen(s);
    for(i=0;i<len;i++)
    {
        a[i].c=s[i];
        a[i].id=i;
        num[s[i]]++;
    }

    sort(a,a+len);
    int maxn=num[a[0].c];
    if((maxn<<1)>len)
        cout<<"impossible"<<endl;
    else{
        for(i=0;i<len;i++)
            ts[(i+maxn)%len]=a[i].c;
        for(i=0;i<len;i++)
            ans[a[i].id]=ts[i];
        //ans[len]='\0';
        cout<<ans<<endl;
    }

    return 0;
}



G1. 唐纳德与子串 (Easy)

Time limit per test: 1.0 seconds

Memory limit: 256 megabytes

子串的定义是在一个字符串中连续出现的一段字符。这里,我们使用  s[lr]  来表示  s  字符串从  l  到  r (闭区间)的子串。在本题中,字符串下标从  0  开始。显然,对于长度为  n  的字符串共有  n(n+1)2  个子串。

对于一个给定的字符串  s ,唐纳德给出  q  次询问,第  i  次询问包括三个参数  li,ri,zi ,问在  s[liri]  的所有子串中共有多少个恰好为  zi

Input

输入具有如下形式:

sql1 r1 z1l2 r2 z2lq rq zq

第一行一个字符串  s

第二行一个整数  q

接下来每行:首先两个整数  li,ri  ( 0liri<|s| ),然后是一个非空字符串  zi 。整数和整数,整数和字符串间以单空格隔开。

字符串中只会出现  26  个小写英文字母。

数据规模约定:

  • 对于 Easy 档: 1|s|100,q|zi|100
  • 对于 Hard 档: 1|s|105,q|zi|105

Output

对于每次询问,输出一个整数,表示答案。

Examples

input
thisisagarbagecompetitionhahaha
5
0 30 a
1 5 is
25 30 hah
6 12 ag
7 12 ag
output
6
2
2
2
1

代码:

#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<cstring>
#include<map>
using namespace std;
typedef long long ll;

int main()
{
    string str,z,temp;
    int q,i,l,r,len,num;
    cin>>str;
    cin>>q;
    while(q--)
    {
        scanf("%d%d",&l,&r);
        cin>>z;
        len=z.length();
        num=0;
        for(i=l;i<=r-len+1;i++)
        {
            temp=str.substr(i,len);
            if(temp==z)
                num++;
        }
        cout<<num<<endl;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值