Helvetic Coding Contest 2018 D1(分数类的使用 && hash)

本文介绍了一种使用分数类和字符串哈希技术来解决叛军舰队在逃避帝国追捕时跳跃到相同坐标的舰船数量统计问题的方法。通过解析算术表达式并利用分数类进行精确计算,确保了坐标的一致性和准确性。

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

problem

The Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independently come up with the coordinate to which that ship will jump. In the obsolete navigation system used by the Rebels, this coordinate is given as the value of an arithmetic expression of the form .

To plan the future of the resistance movement, Princess Heidi needs to know, for each ship, how many ships are going to end up at the same coordinate after the jump. You are her only hope!

Input

The first line of the input contains a single integer m (1 ≤ m ≤ 200 000) – the number of ships. The next m lines describe one jump coordinate each, given as an arithmetic expression. An expression has the form (a+b)/c. Namely, it consists of: an opening parenthesis (, a positive integer a of up to two decimal digits, a plus sign +, a positive integer b of up to two decimal digits, a closing parenthesis ), a slash /, and a positive integer c of up to two decimal digits.

Output

Print a single line consisting of m space-separated integers. The i-th integer should be equal to the number of ships whose coordinate is equal to that of the i-th ship (including the i-th ship itself).

Example

input

4
(99+98)/97
(26+4)/10
(12+33)/15
(5+1)/7

output

1 2 2 1

Note

In the sample testcase, the second and the third ship will both end up at the coordinate 3.

Note that this problem has only two versions – easy and hard.

solution

使用分数类+字符串hash判重

code example

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int debug_num=0;
#define debug cout<<"debug "<<++debug_num<<" :"

unordered_map<string,int> mp;

const int maxn=2e5+10;

ll gcd(ll a,ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}

struct Fraction{
    ll num;
    ll den;
    Fraction (ll num=0,ll den=1){
        if(den<0){
            num=-num;
            den=-den;
        }
        assert(den != 0);
        ll g=gcd(abs(num),den);
        this->num=num/g;
        this->den=den/g;
    }
    Fraction operator + (const Fraction &o) const{
        return Fraction(num*o.den+den*o.num,den*o.den);
    }
    Fraction operator - (const Fraction &o) const{
        return Fraction(num*o.den-den*o.num,den*o.den);
    }
    Fraction operator * (const Fraction &o) const{
        return Fraction(num*o.num,den*o.den);
    }
    Fraction operator / (const Fraction &o) const{
        return Fraction(num*o.den,den*o.num);
    }
    bool operator < (const Fraction &o) const{
        return num*o.den<den*o.num;
    }
    bool operator == (const Fraction &o) const{
        return num*o.den==den*o.num;
    }
}no[maxn];



int main()
{
    //freopen("in.txt","r",stdin);
    //ios::sync_with_stdio(false);
    int m;
    cin>>m;
    //scanf("%d",&m);
    for(int i=0;i<m;++i){
        ll a,b,c;
        //scanf("(%d+%d)/%d",&a,&b,&c);
        //cout<<a<<" "<<b<<" "<<c<<endl;
        string s;
        cin>>s;
        ll sum=0;
        int j;
        for(j=1;j<s.size();++j){
            if(s[j]=='+') break;
            sum=sum*10;
            sum+=s[j]-'0';
        }
        a=sum;
        sum=0;
        j++;
        for(;j<s.size();++j){
            if(s[j]==')') break;
            sum=sum*10;
            sum+=s[j]-'0';
        }
        b=sum;
        sum=0;
        j=j+2;
        for(;j<s.size();++j){
            sum=sum*10;
            sum+=s[j]-'0';
        }
        c=sum;
        no[i]=Fraction(a+b,c);
        s="";
        int tp=no[i].num;
        while(tp){
            s+=tp%10+'0';
            tp/=10;
        }
        s+='_';
        tp=no[i].den;
        while(tp){//逆序就逆序吧...
            s+=tp%10+'0';
            tp/=10;
        }
        mp[s]++;
        //cout<<s<<endl;
    }
    for(int i=0;i<m;++i){
        string s="";
        int tp=no[i].num;
        while(tp){
            s+=tp%10+'0';
            tp/=10;
        }
        s+='_';
        tp=no[i].den;
        while(tp){//逆序就逆序吧...
            s+=tp%10+'0';
            tp/=10;
        }
        cout<<mp[s]<<" ";
    }
    return 0;
}
### 关于CodeForces比赛中“Unrated Allowed”的含义 在CodeForces平台的比赛规则中,“Unrated Allowed”表示该场比赛的结果不会影响参赛者的评级分数(rating)。这意味着无论选手在这场特定比赛中的表现如何——无论是取得了优异的成绩还是未能解决问题——都不会对其全球排名或个人评分产生任何正面或负面的影响[^1]。 具体来说,在被标记为“Unrated Allowed”的竞赛里,所有的参与者都可以自由参加而无需担心因表现不佳而导致评级下降的风险。这种类型的赛事通常用于测试新的题目集、实验不同的比赛形式或者作为社区活动的一部分来吸引更多的编程爱好者参与其中而不必顾虑其正式评价体系下的压力。 例如,在某些情况下,Codeforces会举办一些特别性质的镜像赛(Mirror Contests),如提到过的"Helvetic Coding Contest 2019 online mirror (teams allowed, unrated)"即属于此类情况之一;它允许团队形式报名并明确规定此版本不计入官方成绩统计之中[^2]。另外还有其他例子比如特殊主题挑战赛等也可能采用类似的机制设定。 此外需要注意的是虽然这些未纳入等级考量范围内的比赛提供了更加轻松愉快的学习交流环境给广大程序设计人员们但是它们仍然遵循着严格的时间限制和技术标准要求因此对于希望提升自己技能水平的人来说仍然是非常有价值的经历机会[^3]。 ```python def is_unrated_allowed(contest_type): """ Function to determine if a contest is rated or not based on its type. Args: contest_type (str): The type of the contest as defined by Codeforces. Returns: bool: True if the contest is unrated, False otherwise. """ return contest_type.lower().startswith('unrated') # Example usage print(is_unrated_allowed("Unrated Alpha")) # Expected output: True ```
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值