Codeforces Beta Round #107(Div2)

该博客讨论了两个编程问题。第一个问题是关于从输入的电话号码中统计并输出出租车、披萨店和咖啡馆的最常联系人。第二个问题是关于判断一个数的因子情况,以确定在某种游戏中的胜者。博主分享了他们的解决方案和思路,包括代码实现和错误分析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Codeforces Beta Round #107(Div2)

B - Phone Numbers

这个题思路其实很简单,但是刚开始做的时候想复杂了,代码也写得很复杂。
用一个结构体,存入每个人每种电话出现的次数,对texi、pizza、girl三次遍历统计最多电话种类的个数。然后根据输入的顺序输出。
注意输出格式。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define speed_up ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
struct data
{
    string na;
    int tt;
    int p;
    int g;
}d[105];
int main()
{
    int t;
    cin>>t;
    for(int i=0; i<t; i++)
    {
        int n;
        cin>>n>>d[i].na;
        for(int j=0; j<n; j++)
        {
            string m;
            cin>>m;
            if(m[0]==m[1]&&m[1]==m[3]&&m[3]==m[4]&&m[4]==m[6]&&m[6]==m[7])
            {
                d[i].tt++;
            }
            else if(m[0]>m[1]&&m[1]>m[3]&&m[3]>m[4]&&m[4]>m[6]&&m[6]>m[7])
            {
                d[i].p++;
            }
            else
            {
                d[i].g++;
            }
        }
    }
    int c=0;
    cout<<"If you want to call a taxi, you should call: ";
    for(int i=0;i<t;i++)
    {
        if(d[i].tt>c)c=d[i].tt;
    }
    //cout<<cc<<endl;
    int f=0;
    for(int i=0; i<t; i++)
    {
        if(c==d[i].tt)
        {
            if(f==0)
            {
                cout<<d[i].na;
                f=1;
            }
            else
            {
                cout<<", "<<d[i].na;
            }
        }

    }
    cout<<"."<<endl;

    cout<<"If you want to order a pizza, you should call: ";

    c=0;
    for(int i=0;i<t;i++)
    {
        if(d[i].p>c)c=d[i].p;
    }
    //cout<<cc<<endl;
    f=0;
    for(int i=0; i<t; i++)
    {
        if(c==d[i].p)
        {
            if(f==0)
            {
                cout<<d[i].na;
                f=1;
            }
            else
            {
                cout<<", "<<d[i].na;
            }
        }

    }
    cout<<"."<<endl;
    c=0;
    cout<<"If you want to go to a cafe with a wonderful girl, you should call: ";
    for(int i=0;i<t;i++)
    {
        if(d[i].g>c)c=d[i].g;
    }
    //cout<<cc<<endl;
    f=0;
    for(int i=0; i<t; i++)
    {
        if(c==d[i].g)
        {
            if(f==0)
            {
                cout<<d[i].na;
                f=1;
            }
            else
            {
                cout<<", "<<d[i].na;
            }
        }

    }
    cout<<"."<<endl;
}

C - Win or Freeze

如果是素数就输出:
1
0
有两个以上素数因子:
1赢,输出任意两个素数因子
只有两个因子:2赢
自己写的代码,wa7了

#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define speed_up ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll f(int n)
{
    if(n==2||n==3)
        return 1;
    if(n==1||n%2==0)
        return 0;
    if(n%6!=1&&n%6!=5)
        return 0;
    for(int i=5; i<sqrt(n)+1; i+=6)
    {
        if(i%2==0||(i+1)%2==0)
            return 0;
    }
    return 1;
}
int main()
{
    ll q,x;
    cin>>q;
    if(f(q)||q==1)
        cout<<1<<endl<<0<<endl;
    else
    {
        vector<ll>v;
        int ff=0;
        for(ll i=2; i<sqrt(q)+1; i++)
        {
            while(q%i==0)
            {
                if(f(i))
                {
                    v.push_back(i);
                    cout<<i<<endl;
                }
                q/=i;
            }
            if(f(q))v.push_back(q);
            if(v.size()>2)
            {
                cout<<1<<endl<<v[0]*v[1]<<endl;
                ff=1;
                break;
            }
        }
        if(ff==0)
        {
            cout<<2<<endl;
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值