五一比赛部分题解

2019省赛训练-N+1 

Uint47 calculator

Sample Input

def six 6
def abc 1
def bcd 0
sub bcd abc
add abc six
def universe 0
mul abc six
add universe abc
div bcd six
mod bcd abc
Sample Output

six = 6
abc = 1
bcd = 0
bcd = 140737488355327
abc = 7
universe = 0
abc = 42
universe = 42
bcd = 23456248059221
bcd = 5

注意:注意:在乘的时候可能会超过表示范围,可以加一个循环模拟这个过程。

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
//#define fori(a,b) for(ll i=a;i<=b;i++)
//#define forj(a,b) for(ll j=a;j<=b;j++)
//#define mem(a,b) memset(a,b,sizeof(a))
#define M 140737488355328LL//在这里要加一下LL,否则会编译错误
using namespace std;
typedef long long ll;
mapm;
int main()
{
    m.clear();
   //freopen("//home//acm//桌面//in","r",stdin);
    string s1;
    while(cin >> s1){
        string s2,s3;
        ll k,ans;
        cin >> s2 ;
        if(s1=="add"){
            cin >> s3;
            ans=(m[s2]+m[s3])%M;
        }
        else if(s1=="sub"){
            cin >> s3;
            ans=(m[s2]-m[s3])%M;
        }
        else if(s1=="mul"){
            cin >> s3;
            ll kk=m[s3],flag=1,num=0,a;
            ans=0;
            a=m[s2];
            while(kk){
                if(kk%2)
                    ans+=(a%M*flag%M)%M;
                ans%=M;
                flag*=2;
                flag%=M;
                kk/=2;
                num++;
                if(num>=47)
                    break;
            }
        }
        else if(s1=="div"){
            cin >> s3;
            ans=(m[s2]/m[s3])%M;
        }
        else if(s1=="mod"){
            cin >> s3;
            ans=(m[s2]%m[s3])%M;
        }
        else {
            cin >> k;
            ans=k;
 
        }
        if(ans<0){
            ans+=M;
        }
        m[s2]=ans%M;
        cout <<  s2 << " "<<"="<<" "<

IoU

Sample Input
 
2
1 1 1 1
1 1 2 2
1 1 2 1
1 1 1 2
Sample Output
 
0.25
0.33

题意:给出两组x,y,w,h,分别组成两个矩形,求交集的面积比上并集的面积。

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
//#define fori(a,b) for(ll i=a;i<=b;i++)
//#define forj(a,b) for(ll j=a;j<=b;j++)
//#define mem(a,b) memset(a,b,sizeof(a))
#define M 140737488355328LL
using namespace std;
typedef long long ll;
struct node
{
    double x,y,w,h;
}a,b;
int main()
{
 
   //freopen("//home//acm//桌面//in","r",stdin);
    int t;
    cin >> t;
    while(t--){
        double w,h;
        cin >> a.x >> a.y >> a.w >> a.h;
        cin >> b.x >> b.y >> b.w >> b.h;
        if(a.x>b.x)
            swap(a,b);
        if(b.x>=a.x+a.w||b.y>=a.y+a.h||b.y+b.h<=a.y){
            printf("0.00\n");
            continue;
        }
        if(b.x+b.w<=a.x+a.w)
            w=b.w;
        else
            w=a.x+a.w-b.x;
 
        if(b.y+b.h<=a.y+a.h){
            if(b.y

 

2019省赛训练-N+2 

Two Fashillows

Description

Haneen and Reem are working on their graduation project. The deadline for submitting the final project is after d hours. They need at least w hours of work to finish it. So now they are thinking of skipping PSUT Coding Marathon V. Yaslo7oon? La yaslo7oon.

The Marathon will consume m hours of their time.

They will participate in the marathon if any of the two following cases can happen: first, if the time they have is enough for them to participate and finish the project in time, second, if they won't finish the project anyway even if they didn't participate.

Determine whether they should participate in the marathon or not.

Input

The input contains three integers dw and m (1 ≤ d, w, m ≤ 1000), the number of hours before the deadline, the number of working hours needed to finish the project, and the number of hours the marathon takes.

Output

Print "good luck" if they should participate, and "see you next semester" if they should not.

All letters in the output must be in lowercase. Do not print extra characters.

Sample Input

Input

48 879 7
Output

good luck
Input

48 41 8
Output

see you next semester

题意:a是工程提交截止的时间,b是工程需要的时间,c跑马拉松需要的时间,问可以跑马拉松吗(能跑马拉松有两个条件,第一:跑马拉松也能完成任务,二:即使不跑也完不成任务)

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
//#define fori(a,b) for(ll i=a;i<=b;i++)
//#define forj(a,b) for(ll j=a;j<=b;j++)
//#define mem(a,b) memset(a,b,sizeof(a))
//#define M 140737488355328LL
using namespace std;
typedef long long ll;
const int mmax=2e6+10;
int main()
{


    //freopen("//home//acm//桌面//in","r",stdin);
    int a,b,c;
    cin >> a >> b >> c;
    if(a=b&&c+b<=a))
        cout << "good luck"<

Two Palindromes

Sample Input

Input
abba
qq
Output
YES
Input
a
c
Output
NO
Input
bab
weew
Output
YES

题意:给出两个回文串,问将第2个串插入第一个串中还是回文吗?

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
//#define fori(a,b) for(ll i=a;i<=b;i++)
//#define forj(a,b) for(ll j=a;j<=b;j++)
//#define mem(a,b) memset(a,b,sizeof(a))
//#define M 140737488355328LL
using namespace std;
typedef long long ll;
const int mmax=1e5+10;
mapy;
int main()
{


    //freopen("//home//acm//桌面//in","r",stdin);
    string s1,s2;
    cin >> s1 >> s2;
    int len1=s1.size();
    int len2=s2.size();
    if(len1%2==0||len2%2==0){
        cout << "YES" <

 Forest (A) - Egg

Sample Input

Input
3
2 1 3
Output
2
Input
5
5 4 3 2 1
Output
1
Input
1
1
Output
1

题意:问可以形成几棵树,形成数的条件是the parent of node i is j, where j is the maximum index such that j < i and Aj > Ai. If such index doesn't exist, then node i has no parent. 

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
//#define fori(a,b) for(ll i=a;i<=b;i++)
//#define forj(a,b) for(ll j=a;j<=b;j++)
//#define mem(a,b) memset(a,b,sizeof(a))
//#define M 140737488355328LL
using namespace std;
typedef long long ll;
const int mmax=2e6+10;
int main()
{
    //freopen("//home//acm//桌面//in","r",stdin);
    int n,p,a,ans=1;
    cin >> n;
    scanf("%d",&p);
    for(int i=1;ip){
            ans++;
            p=a;
        }
    }
    cout << ans << endl;
    return 0;
}

World Mug (A) 

 

题意:求除去第一层相邻两数差的和。 

Sample Input

Input
8
100 200 300 400 800 700 600 500
Output
1200
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
//#define fori(a,b) for(ll i=a;i<=b;i++)
//#define forj(a,b) for(ll j=a;j<=b;j++)
//#define mem(a,b) memset(a,b,sizeof(a))
//#define M 140737488355328LL
using namespace std;
typedef long long ll;
const ll mmax=1e6+10;
ll a[mmax],ans=0;
ll ss(ll l,ll r)
{
    if(l+1==r){
        ans+=abs(a[r]-a[l]);
        return max(a[r],a[l]);
    }
    ll mid=(l+r)/2;
    ll lmax=ss(l,mid);
    ll rmax=ss(mid+1,r);
    ans+=abs(lmax-rmax);
    return max(lmax,rmax);
}
int main()
{
    //freopen("//home//acm//桌面//in","r",stdin);
    ll n;
    scanf("%lld",&n);
    for(ll i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    ll t=ss(1,n);
    cout <

World Mug (B)

Input
8
100 200 300 400 800 700 600 500
Output
2100

题意:跟上题类似,求一种排列方式,使得按上题求法的和最大,问最大的和是多少。

思路:先排序,变成800 700 600 500 400 300 200 100,每次两边的位置对应起来差的和最大,最后上一层就变成了800 700 600,重复这个过程就可以了。

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define MAX 0x3f3f3f3f
#define fori(a,b) for(int i=a;i<=b;i++)
#define forj(a,b) for(int j=a;j<=b;j++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const int M=1e6+10;
const int mod=1e9+7;
ll a[M];
ll cmp(ll p,ll q)
{
    return p>q;
}
int main()
{
    ll n,i;
    scanf("%lld",&n);
    for(i=0;i1)
    {
        for(i=0;i

2019省赛训练-N+3

Dice Cup

Sample Input
6 6
6 4
12 20
Sample Output
7

5
6
7

13
14
15
16
17
18
19
20
21

题意:给出两个骰子,面数分别为n,m,求面数之和可能性最大的和。

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
//#define fori(a,b) for(ll i=a;i<=b;i++)
//#define forj(a,b) for(ll j=a;j<=b;j++)
//#define mem(a,b) memset(a,b,sizeof(a))
//#define M 140737488355328LL
using namespace std;
typedef long long ll;
const int M=1e5+10;
int f[M],num[M],b[M];
queueq;
int main()
{
    //freopen("//home//acm//桌面//in","r",stdin);
    int n,m;
    cin >> n >> m;
    if(n>m)
        swap(n,m);
    for(int i=n+1;i<=m+1;i++)
            cout << i <> n >> m){
        cout << endl;
        if(n>m)
            swap(n,m);
        for(int i=n+1;i<=m+1;i++)
            cout << i <

2019省赛训练-N+4

Array Reconstructing​​​​​​​

Input
4
5 10
1 2 3 4 5
4 10
7 -1 9 -1
6 7
5 -1 -1 1 2 3
6 10
5 -1 7 -1 9 0
Output
1 2 3 4 5
7 8 9 0
5 6 0 1 2 3
5 6 7 8 9 0

题意:ai = ( ai - 1 + 1) % m, for each i (1 < i ≤ n),求-1位置上的是什么。

 

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define MAX 0x3f3f3f3f
#define fori(a,b) for(int i=a;i<=b;i++)
#define forj(a,b) for(int j=a;j<=b;j++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
const double PI = acos(-1);
const int M=1e3+10;
int a[M];
int main()
{
    //freopen("//home//acm//桌面//in","r",stdin);
    int n,t,m;
    scanf("%d",&t);
    while(t--)
    {
        int pos=0,flag=0;
        scanf("%d%d",&n,&m);
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&a[i]);
            if(a[i]==-1){
                if(a[i-1]!=-1){
                    a[i]=(a[i-1]+1)%m;
                }
            }
            else if(a[i]!=-1&&!flag){
                pos=i;
                flag=1;
            }
        }
        //cout << pos <=1;i--){
            a[i]=(a[i+1]-1+m)%m;
        }
        for(int i=1;i<=n;i++)
        {
            if(i==1)
                printf("%d",a[i]);
            else
                printf(" %d",a[i]);
        }
        printf("\n");
    }

    return 0;
}

 Counting Test

Input
1
8 5
abcabdca
1 8 c
1 15 b
4 9 a
5 25 d
2 7 c
Output
2
4
3
3
2

题意:给出一个范围,问在这个范围内字母出现了几次。

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define MAX 0x3f3f3f3f
#define fori(a,b) for(int i=a;i<=b;i++)
#define forj(a,b) for(int j=a;j<=b;j++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
const double PI = acos(-1);
const int M=1e4+10;
const int mod=1e9+7;
int num[M][200],p[200];
char s[M];
int main()
{
    //freopen("//home//acm//桌面//in","r",stdin);
    int n,t,q;
    scanf("%d",&t);
    while(t--)
    {
        mem(num,0);
        mem(p,0);
        scanf("%d%d",&n,&q);
        // getchar();
        scanf("%s",s);
        //  cout << s <

Magical Indices

Input
2
8
2 1 3 4 6 5 7 9
6
4 2 7 9 8 10
Output
3
1

题意:

  1. 1 < x < n
  2. ay ≤ ax, for each y(1 ≤ y < x).
  3. ax ≤ az, for each z(x < z ≤ n).
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define MAX 0x3f3f3f3f
#define fori(a,b) for(int i=a;i<=b;i++)
#define forj(a,b) for(int j=a;j<=b;j++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
const double PI = acos(-1);
const int M=1e6+10;
int a[M],b[M];
int main()
{
    //freopen("//home//acm//桌面//in","r",stdin);
    int n,t,m;
    scanf("%d",&t);
    while(t--)
    {
       int n,ans=0;
       scanf("%d",&n);
       for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
       }
       b[n]=a[n];
       for(int i=n-1;i>=2;i--){
            if(a[i]=l&&a[i]<=b[i+1])
                ans++;
            if(a[i]>l)
                l=a[i];
       }
       printf("%d\n",ans);
    }

    return 0;
}

Corrupted Images

Input
3
3 3
111
101
111
4 4
1111
0111
1000
1111
4 5
10101
01010
10101
01010
Output
0
2
-1

题意:问可以通过交换任意位置的0 1 变成外围全为1的图案吗,不能输出-1,能输出最小步数。

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define MAX 0x3f3f3f3f
#define fori(a,b) for(int i=a;i<=b;i++)
#define forj(a,b) for(int j=a;j<=b;j++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
const double PI = acos(-1);
const int M=100;
const int mod=1e9+7;
char a[M][M],b[M];

int main()
{
    //freopen("//home//acm//桌面//in","r",stdin);
    int n,t,m;
    scanf("%d",&t);
    while(t--)
    {
       int n,m,y1=0,y2=0;
       scanf("%d%d",&n,&m);
       for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                cin >> a[i][j];
                if((i==1||i==n||j==1||j==m)&&a[i][j]=='1')
                    y1++;
                else if(a[i][j]=='1')
                    y2++;
            }
       }
      // cout << y1 << " "<

Palindromes Building

Input
5
4
aabb
6
ababbc
6
abaaba
12
babacbcbcaca
14
aaaabbcaaaabbc
Output
2
0
3
90
105

题意:给出一个串,可以交换任意字符,问有几种方式使得为回文串。

思路:可以用截半法,用一个数组记录每个字母出现的个数,当有两个以上的奇数的时候,肯定为0,有一个奇数的时候,可以把那一个放到最中间,该字符出现次数减一,其他除以2,比如ababc,最后变成了a有1个,b有一个,在计算ab组合的数量;当都是偶数的时候,出现次数/2,比如说aaaabbcaaaabbc,操作完之后变成了a有4个, b有2个, c有1个,组合方式为C(7,4)*C(3,2)*C(1,1).

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define MAX 0x3f3f3f3f
#define fori(a,b) for(int i=a;i<=b;i++)
#define forj(a,b) for(int j=a;j<=b;j++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const int M=1e4+10;
const int mod=1e9+7;
ll c[21][21],a[21];
int main()
{
    ll i,j,t;
    memset(c,0,sizeof(c));
    a[0] = 1;
    a[1]=1;
    for(i=2;i<=20;i++)
        a[i]=a[i-1]*i;
    memset(c,0,sizeof(c));
    for(i=1;i<=20;i++)//n
    {
        for(j=0;j<=i;j++)//m
        {
            c[i][j] = a[i] / (a[i-j] * a[j]);
        }
    }
    cin>>t;
    while(t--)
    {
        string s;
        ll n,ans=0;
        cin>>n>>s;
        ll num[30];
        ll len=s.size();
        memset(num,0,sizeof(num));
        for(i=0;i=2)
            cout<<"0"<

2019省赛训练-N+5

World Cup

题意:有4个人比赛,分别与其他3人进行比赛,给出最终结果,问能否确定有唯一一种可能,是YES,不是NO,没有这种情况输出Wrong Scoreboard

Sample Input
3
9 6 3 0
6 6 6 0
10 6 3 0
Sample Output
Case #1: Yes
Case #2: No
Case #3: Wrong Scoreboard
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define MAX 0x3f3f3f3f
#define fori(a,b) for(int i=a;i<=b;i++)
#define forj(a,b) for(int j=a;j<=b;j++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
const double PI = acos(-1);
const int M=1e4+10;
const int mod=1e9+7;
int main()
{
    //freopen("//home//acm//桌面//in","r",stdin);
    int n,t,q;
    scanf("%d",&t);
    for(int u=1; u<=t; u++)
    {
        int a,b,c,d,ans=0;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        int A=0,B=0,C=0,D=0;
        int aa1,bb1,cc1,dd1,aa2,bb2,cc2,dd2,aa3,bb3,cc3,dd3;
        int aa4,bb4,cc4,dd4,aa5,bb5,cc5,dd5;
        for(int a1=1; a1<=3; a1++)
        {
            A=0,B=0,C=0,D=0;
            if(a1==1)
                A=3;
            if(a1==2)
                A=1,B=1;
            if(a1==3)
                B=3;
            aa1=A,bb1=B,cc1=C,dd1=D;
            for(int a2=1; a2<=3; a2++)
            {
                A=aa1,B=bb1,C=cc1,D=dd1;
                if(a2==1)
                    A+=3;
                if(a2==2){
                    A+=1;
                    C+=1;
                }
                if(a2==3)
                    C+=3;
                aa2=A,bb2=B,cc2=C,dd2=D;
                for(int a3=1; a3<=3; a3++)
                {
                    A=aa2,B=bb2,C=cc2,D=dd2;
                    if(a3==1)
                        A+=3;
                    if(a3==2){
                        A+=1;
                        D+=1;
                    }
                    if(a3==3)
                        D+=3;
                    aa3=A,bb3=B,cc3=C,dd3=D;
                    for(int a4=1; a4<=3; a4++)
                    {
                        A=aa3,B=bb3,C=cc3,D=dd3;
                        if(a4==1)
                            B+=3;
                        if(a4==2){
                            B+=1;C+=1;

                        }
                        if(a4==3)
                            C+=3;
                        aa4=A,bb4=B,cc4=C,dd4=D;
                        for(int a5=1; a5<=3; a5++)
                        {
                            A=aa4,B=bb4,C=cc4,D=dd4;
                            if(a5==1)
                                B+=3;
                            if(a5==2){
                                B+=1;D+=1;

                            }
                            if(a5==3)
                                D+=3;
                            aa5=A,bb5=B,cc5=C,dd5=D;
                            for(int a6=1; a6<=3; a6++)
                            {
                                A=aa5,B=bb5,C=cc5,D=dd5;
                                if(a6==1)
                                    C+=3;
                                if(a6==2){
                                    C+=1;
                                    D+=1;

                                }
                                if(a6==3)
                                    D+=3;
                              //  cout << A << " " << B << " " << C << " "<< D<

 

你可能感兴趣的:(组队赛)