Quiz
https://yukicoder.me/problems/no/1076
解説
- editorialのように方程式一発でやるとかっこいい
- でも今回は基本に立ち返って求めてみると、以下のようになります
- 「等比数列の和の公式」を使いました
https://yukicoder.me/problems/no/1076
3パターン書いてみた。
// a.cpp #include<bits/stdc++.h> using namespace std; int main(){ cout << "I am a's output" << endl; return 0; }
// b.cpp #include<bits/stdc++.h> using namespace std; int main(){ string s; getline(cin, s); cout << "b got a message " << s << endl; return 0; }
// コンパイル g++ a.cpp -o a.out g++ b.cpp -o b.out
// パイプでつなげる(aの出力をbの入力とする) ./a.out | ./b.out // 出力(ターミナルの表示)はこうなる b got a message I am a's output
#include<bits/stdc++.h> using namespace std; struct History{ int v; string url; string title; bool operator<(const History &another) const{ return v < another.v; } }; int main(){ vector<History> H; H.push_back({2,"aaa","bbb"}); H.push_back({1,"ccc","ddd"}); H.push_back({4,"eee","fff"}); H.push_back({3,"ggg","hhh"}); sort(H.begin(), H.end()); for(auto h : H){ cout << h.v << ' ' << h.url << ' ' << h.title << endl; } return 0; }
1 ccc ddd 2 aaa bbb 3 ggg hhh 4 eee fff
// 判別式 ll discriminant(ll a, ll b, ll c){ return b*b - 4*a*c; } // 2次方程式の解(x1, x2) pair<ld,ld> quadratic_equation(ll a, ll b, ll c){ ll D = discriminant(a,b,c); ld x1 = (-b-sqrt(D))/(2*a); ld x2 = (-b+sqrt(D))/(2*a); return {x1,x2}; } // 2点を通る直線を求める(係数 (a,b) を返す) // y = ax + b pair<ld,ld> line_from_two_point(ld x1, ld y1, ld x2, ld y2){ if(x1==x2){ // y軸と平行な直線 cerr << "TODO"; exit(0); } if(y1==y2){ // x軸と平行な直線 return {0, y1}; } // 傾き ld tilt = (y2-y1)/(x2-x1); ld a = tilt; ld b = a * (-x1) + y1; return {a,b}; }
https://atcoder.jp/contests/past202004-open/tasks/past202004_h
https://atcoder.jp/contests/past202004-open/submissions/13146204