본문 바로가기

알고리즘49

Tree #include using namespace std; typedef long long ll; const int MAX = 100001; int parent[MAX]; struct Tree { int root, size; vector child[MAX], edge[MAX]; Tree() { root = -1; size = 0; } Tree(int n) { root = -1; size = n; } void addEdge(int u, int v) { edge[u].push_back(v); edge[v].push_back(u); } void build(int id) { if (root == -1) root = id; for (int next : edge[id]) { if (!parent[next]) { pare.. 2020. 8. 6.
Codeforces Round #660 (Div. 2) AB from sys import stdin T=int(stdin.readline()) for _ in range(T): n=int(stdin.readline()) if n 2020. 8. 6.
Educational Codeforces Round 92 (Rated for Div. 2) A from sys import stdin from math import gcd def lcm(a, b): return a * b / gcd(a, b) T=int(stdin.readline()) for _ in range(T): l,r=map(int,stdin.readline().split()) if l==1: print(1,2) else: if lcm(l,int(l*(1.5))) 2020. 8. 6.
Codeforces Round #658 (Div. 2) AB from sys import stdin T=int(stdin.readline()) A=[] B=[] for _ in range(T): n,m=map(int,stdin.readline().split()) A=list(map(int,stdin.readline().split())) B=list(map(int,stdin.readline().split())) res=list(set(A) & set(B)) if len(res)==0: print("NO") else: print("YES") print(1,res[0]) A - Common Subsequence from sys import stdin T=int(stdin.readline()) for _ in range(T): cnt=0 N=int(stdin.readli.. 2020. 8. 6.
Codeforces Round #661 (Div. 3) ABC from sys import stdin def input(): return stdin.readline().rstrip() for _ in range(int(input())): n=int(input()) s=sorted(list(map(int,input().split()))) if len(s)==1: print("YES") else: flag=True for i in range(n): if s[i]-s[i-1]>1: flag=False if flag: print("YES") else: print("NO") A - Remove Smallest from sys import stdin def input(): return stdin.readline().rstrip() for _ in range(int(input(.. 2020. 8. 6.
Codeforces Round #656 (Div. 3) ABC #include #include using namespace std; int T, x, y, z; int a[3]; int main() { cin.tie(NULL); cout.tie(NULL); ios::sync_with_stdio(0); cin >> T; while (T--) { cin >> a[0] >> a[1] >> a[2]; sort(a, a + 3); if (a[1] != a[2]) { cout a[i - 1]) slope = -1; else if (a[i] a[i - 1.. 2020. 8. 6.