Day07比赛总结

· · 个人记录

day07 比赛总结

得分情况与用时

A: 40分,用时约15分钟

B: 0分,用时约35分钟

C: 0分,用时约40分钟

D: 0分,用时约30分钟

A题题目解析

题意

给定两个日期,求两个日期范围内有多少个回文日期。

日期由8位数字组成:

年份4位 + 月份2位 + 日期2位。

思路

其实模拟也能过,但是其实可以发现每年最多只有一个回文日期,所以可以直接看给出的date1和date2之间包含了几个回文日期

代码

#include <bits/stdc++.h>
#define int long long
using namespace std;
string date1,date2;
string nf="",yf="",rf="",rq="";
int nian,yue,ri;
int cnt;
int yr[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int yp[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
string date()
{
    ri++;
    if(nian%4==0&&nian%100!=0||nian%400==0)
    {
        if(ri>yr[yue])
        {
            ri=1;
            yue++;
        }
        if(yue>12)
        {
            yue=1;
            nian++;
        }
    }
    else
    {
        if(ri>yp[yue])
        {
            ri=1;
            yue++;
        }
        if(yue>12)
        {
            yue=1;
            nian++;
        }
    }
    nf=to_string(nian);
    yf=to_string(yue);
    rf=to_string(ri);
    if(ri<10)rf="0"+rf;
    if(yue<10)yf="0"+yf;
    rq=nf+yf+rf;
    return rq;
}
bool check(string a)
{
    reverse(a.begin()+4,a.end());
    string b2="";
    string b1="";
    b1+=a[0];
    b1+=a[1];
    b1+=a[2];
    b1+=a[3];
    b2+=a[4];
    b2+=a[5];
    b2+=a[6];
    b2+=a[7];
    if(b1==b2)
    {
        return 1;
    }
    return 0;
}

signed main()
{
//  freopen("date.in","r",stdin);
//  freopen("date.out","w",stdout);
    cin>>date1>>date2;
    string yyyy="";
    yyyy+=date1[0];
    yyyy+=date1[1];
    yyyy+=date1[2];
    yyyy+=date1[3];
    nian=stoi(yyyy);
    string mm="",dd="";
    mm+=date1[4];
    mm+=date1[5];
    dd+=date1[6];
    dd+=date1[7];
    yue=stoi(mm);
    ri=stoi(dd);
    string i=date1;
    while(1)
    {
//      cout<<i<<endl;
        if(check(i))
        {
            cnt++;
        }
        if(i==date2)break;
        i=date();
    }
    cout<<cnt;
    return 0;
}

个人总结

这一题损失巨大,肝了一整场考试然后输在了一个判断的位置错误上,然后60分的特殊性质分也没拿到(大悲

B题题目解析

题意

模拟地铁和公交换乘。

地铁:

公交:

思路

维护优惠券的信息 过期的和用过的就不要了,没过期和用的的就看能不能用,能用就用了

代码

#include<bits/stdc++.h>
using namespace std;
bool used[100005];
int price[100005],t[100005]; 
int n,m,sum=0,head;
int main() 
{
    cin>>n;
    for(int i=0;i<n;i++) 
    {
        int op,p,q;
        cin>>op>>p>>q;
        if(op==0) 
        {
            sum+=p;
            price[m]=p;
            t[m]=q+45;
            m++; 
        }
        else
        {
            while(t[head]<q&&head<m)
            {
                head++;
            }
            bool f=1;
            for(int j=head;j<m;j++) 
            {  
                if(price[j]>=p&&t[j]>=q&&used[j]==0) 
                {
                    used[j]=1;
                    f=0;
                    break;
                }
            }
            if(f==1)
            {
                sum+=p;
            }
        }
    }
    cout<<sum;
    return 0;
}

个人总结

这道题没写,其实就是模拟,该拿的分没拿到

C题题目解析

题意

模拟网络连接。

Server:

Client:

需要判断:

暴力思路

因为特殊性质1不存在不合规的地址

所以我们直接判断地址是否重复和存在就行

代码

#include <bits/stdc++.h>
#define int long long
using namespace std;
string ad[1005];
int id[1005];
int cnt;
signed main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        string op,s;
        cin>>op>>s;
        if(op=="Server")
        {
            bool ok=true;
            for(int j=1;j<=cnt;j++)
            {
                if(ad[j]==s)
                {
                    ok=false;
                    break;
                }
            }
            if(ok)
            {
                cnt++;
                ad[cnt]=s;
                id[cnt]=i;
                cout<<"OK"<<endl;
            }
            else
            {
                cout<<"FAIL"<<endl;
            }
        }
        else
        {
            int ans=0;
            for(int j=1;j<=cnt;j++)
            {
                if(ad[j]==s)
                {
                    ans=id[j];
                    break;
                }
            }
            if(ans!=0)cout<<ans<<endl;
            else cout<<"FAIL"<<endl;
        }
    }
    return 0;
}

个人总结

又是暴力55分没拿到

D题题目解析

题意

给定颜色和数字。

寻找满足:

的三元组。

暴力思路

三重循环枚举判断是否为三元组

代码

#include<bits/stdc++.h>
#define int long long
using namespace std;

int n,m;
int num[100005],color[100005];

signed main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>num[i];
    for(int i=1;i<=n;i++)cin>>color[i];
    int ans=0;
    for(int x=1;x<=n;x++)
    {
        for(int y=x+1;y<=n;y++)
        {
            for(int z=y+1;z<=n;z++)
            {
                if(y-x==z-y&&color[x]==color[z])
                {
                    ans+=(x+z)*(num[x]+num[z]);
                    ans%=10007;
                }
            }
        }
    }
    cout<<ans;
    return 0;
}

个人总结

20分qwq

整场考试总结

明天不能只肝一道题了,先把能拿到的分拿到手再去优化