Helvetic Coding Contest 2018 D1
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
using namespace std; typedef long long ll; int debug_num=0;
define debug cout<<"debug "<<++debug_num<<" :"
unordered_map 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
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'; tp=no[i].den; while(tp){//逆序就逆序吧... s+=tp%10+'0'; tp/=10; } mp[s]++; //cout<'; tp=no[i].den; while(tp){//逆序就逆序吧... s+=tp%10+'0'; tp/=10; } cout<
相關文章
- 2018 Multi-University Training Contest 3 - HDU ContestAI
- North American Invitational Programming Contest 2018
- 2018 China Collegiate Programming Contest Final (CCPC-Final 2018)
- Petrozavodsk Winter-2018. Jagiellonian U Contest
- Petrozavodsk Winter-2018. Carnegie Mellon U Contest
- JAVASE簡介---D1Java
- 2018-2019 ACM-ICPC, Asia Seoul Regional Contest——A - CircuitsACMUI
- CF2002 D1/2
- 2018-2019 ACM-ICPC, China Multi-Provincial Collegiate Programming ContestACM
- 2018 Multi-University Training Contest 9----hdu 6415 Rikka with Nash EquilibriumAIUI
- Happy coding ! lol?APP
- IOI D1 T2 message
- 2018 BACS Regional Programming Contest C. BACS, Scoundrel Shopkeeper and Contiguous Sequence (模擬)
- 2024 (ICPC) Jiangxi Provincial Contest -- Official Contest
- The Coding Kata: FizzBuzzWhizz in Scala
- AISing Programming Contest 2021(AtCoder Beginner Contest 202)AI
- Mynavi Programming Contest 2021(AtCoder Beginner Contest 201)
- Cloudflare D1 - 免費資料儲存Cloud
- 使用wrangler建立hono和D1的Worker
- The 2024 CCPC Shandong Invitational Contest and Provincial Collegiate Programming Contest
- coding第10天1.4
- coding第8天1.1
- 讀 《CSharp Coding Guidelines》有感CSharpGUIIDE
- Toyota Programming Contest 2024#11(AtCoder Beginner Contest 379)
- KEYENCE Programming Contest 2024(AtCoder Beginner Contest 374)題解
- Toyota Programming Contest 2024#7(AtCoder Beginner Contest 362)
- Toyota Programming Contest 2024#3(AtCoder Beginner Contest 344)
- UNIQUE VISION Programming Contest 2024 Spring(AtCoder Beginner Contest 346)Spring
- nowcoder Week Contest
- Weekly Contest 387
- AspNetCore&Coding持續整合NetCore
- acm-(區間dp、迴文串、子序列)ICPC SG Preliminary Contest 2018 C - Making PalindromesACM
- Toyota Programming Contest 2024#11(AtCoder Beginner Contest 379)題解
- Hitachi Vantara Programming Contest 2024(AtCoder Beginner Contest 368)題解A~D
- Hitachi Vantara Programming Contest 2024(AtCoder Beginner Contest 368)F - Dividing GameGAM
- AtCoder Beginner Contest 382
- AtCoder Beginner Contest 381
- AtCoder Beginner Contest 379