A. Who is better?
碩哥的代碼
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
map<LL,int> mp;
LL exgcd(LL a, LL b, LL &x, LL &y)
{
if(b==0)
{
x=1;
y=0;
return a;
}
LL d = exgcd(b,a%b,y,x);
y -= a/b*x;
return d;
}
int main()
{
int n;
cin >>n;
LL m1,a1,x;
cin >> a1>>m1;
bool has=true;
for(int i=1;i<n;i++)
{
LL m2,a2;
cin >> a2 >> m2;
LL k1,k2;
LL d = exgcd(a1,a2,k1,k2);
if((m2-m1)%d)
{
has = false;
break;
}
k1 *=(m2-m1)/d;
LL t = a2/d;
k1 = (k1%t+t)%t;
m1 = k1 *a1 + m1;
a1 = abs(a1/d *a2);
}
LL a = 2, b = 3;
mp[a] = 1;
mp[b] = 1;
for(int i = 0; i < 100; i++){
LL c = a + b;
if(c > 1e16)
break;
mp[c] = 1;
a = b, b = c;
}
if(has)
{
if(mp[m1])
cout << "Lbnb!" << endl;
else
cout << "Zgxnb!" << endl;
}
else
{
cout << "Tankernb!" << endl;
}
return 0;
}
B. so easy
應該是學姐的代碼
#include <bits/stdc++.h>
#include<tr1/unordered_map>
using namespace std::tr1;
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
typedef pair<int, int> pii;
int main()
{
unordered_map<int, bool> mmp;
int n, q, l, r;
scanf("%d %d", &n, &q);
while(q--) {
scanf("%d %d", &l, &r);
if(l == 1) {
mmp[r] = true;
} else {
int i = r;
while(mmp[i]) ++i;
printf("%d\n", i);
}
}
return 0;
}
C. Buy Watermelon
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main(void)
{
int w;
scanf("%d", &w);
if (w % 2 == 0 && w != 2)
printf("YES\n");
else
printf("NO\n");
return 0;
}
D. Carneginon
楊dalao的代碼
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(void)
{
int t;
string str, s;
cin >> str;
cin >> t;
while(t--){
cin >> s;
if(s.size() == str.size()){
if(s == str)puts("jntm!");
else puts("friend!");
}
else if(s.size() < str.size()){
int x = str.find(s);
if(x >= 0 && x < str.size())puts("my child!");
else puts("oh, child!");
}
else{
int x = s.find(str);
if(x >= 0 && x < s.size())puts("my teacher!");
else puts("senior!");
}
}
return 0;
}