A

Test instructions: Give a number n, to satisfy A+b=n, and a+b are composite, A, B

Method One: The i,n-i can be enumerated directly to determine whether the a,n-i is composite

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <stack>6#include <vector>7#include <map>8#include <algorithm>9 #definemod=1e9+7;Ten using namespacestd; One AtypedefLong LongLL; - BOOLisp[1001000]; - the voidIsPrime () { -isp[1]=isp[0]=true; - for(intI=2; i<=1000010; i++){ - if(isp[i]==false) + for(intj=i*2; j<=1000010; j+=i) -isp[j]=true; + } A } at - intMain () - { - intN; -Cin>>N; - IsPrime (); in for(intI=2; i<=n;i++){ - if(isp[i]&&isp[n-i]) { toprintf"%d%d\n", i,n-i); + Break; - } the } * return 0; $}

View Code

Method Two: Notice the n>=12, while the 4 is the smallest composite,

So: when n is odd, then n-9 is at least 4 composite, output 9,n-9

When n is an even number, then the n-8 is at least 4 composite, and the output 8,n-8

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <stack>6#include <vector>7#include <map>8#include <algorithm>9 #definemod=1e9+7;Ten using namespacestd; One AtypedefLong LongLL; - - intMain () { the intN; -Cin>>N; - if(n%2) printf ("%d%d\n",9, N-9); - Elseprintf"%d%d\n",8, N-8); + return 0; -}

View Code

B

Test instructions: Give an elevator, give n people, n people to go to the floor a[i], and elevator each time the maximum number of people can load K, asked to send everyone to the target floor, it takes the least time

Look at the question of the question: first group K individuals and this K person to go to the highest floor of the person on the same elevator, and then the second group of k individuals and this K-person inside the floor to go to the highest level of people on the same elevator,

So the total time is ans=2* ((a[n]-1) + (a[n-k]-1) +a[n-2k]-1)----

So the first sort, and then back to take the number of k, so as to minimize the next time to transport people, the proof of the people did not see clearly =

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <stack>6#include <vector>7#include <map>8#include <algorithm>9 #definemod=1e9+7;Ten using namespacestd; One AtypedefLong LongLL; - inta[100050]; - the intMain () { - intn,k,i,j,ans=0; -Cin>>n>>K; - for(i=1; i<=n;i++) cin>>A[i]; +Sort (A +1, a+n+1); - for(i=n;i>=1; i=i-k) { +ans+= (a[i]-1)*2; A } atprintf"%d\n", ans); - return 0; -}

View Code

C

Test instructions: Give n person's surname, and first name, arbitrarily select one of them as a sort of keyword, ask whether can satisfy the given sequence.

According to the given sequence to traverse, first a[i],b[i] sorted into small in front, large in the after, if A[i] is greater than the current cur, then a[i] assigned to cur, otherwise b[i] assigned to cur, are not satisfied with the words is "no" is to choose A[i],b[i] The smaller as the keyword

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <stack>6#include <vector>7#include <map>8#include <algorithm>9 #definemod=1e9+7;Ten using namespacestd; One AtypedefLong LongLL; - stringa[100050],b[100050]; - intp[100050]; the stringCur=""; - - intMain () - { + intn,i,j; -Cin>>N; + for(i=0; i<n;i++) cin>>a[i]>>B[i]; A for(i=0; i<n;i++) { atCin>>P[i]; -p[i]--; - } - - for(i=0; i<n;i++){ - intx=P[i]; in if(a[x]>b[x]) swap (a[x],b[x]); - if(Cur<a[x]) cur=A[x]; to Else if(Cur<b[x]) cur=B[x]; + Else{ -printf"no\n"); the return 0; * } $ }Panax Notoginsengprintf"yes\n"); - return 0; the}

View Code

D

Test instructions: gives a matrix that asks if the matrix can be composed of a tree with weights

First build with Prim, then enumerate the distance of each node to the other node, and see if it is the same as the given matrix.

I don't know how to write = =

Codeforces Round #270