時間的な都合でしばらくはTopCoderに参加できないので,Codeforcesに参加してきました.
Codeforcesは,SRM(TopCoder)のようなプログラミングコンテストの一つで,形式はICPCに近い感じです.SRMと違うと感じた点は,
・SRMが3問75分であるのに対し,Codeforcesは基本的に5問120分.
・SRMのように参加者をルーム毎に分けない.
・データの受け渡しには標準入出力を使う
・コードを提出したら,即座にシステムテストが行われる.また,テストに落ちても再提出できる.
・↑のため,Challenge PhaseやSystem Testが無い.
といった所です.
A Noldbach problem
正整数kとnが与えられる.2からnまでの素数で,
1+(i番目の素数)+(i+1番目の素数)
という形で表現出来るものがk個以上ある場合は"Yes",そうでない時は"No"と出力せよ.
値の範囲が,2≦n≦1000,0≦k≦1000と狭かったため,簡単な実装ゲーでした.
- import java.util.*;
- public class A{
- void exe(){
- LinkedList<Integer> list=new LinkedList<Integer>();
- for(int i=2; i<=1000; i++)
- if(isPrime(i))
- list.add(i);
- Object[] primes=list.toArray();
- Scanner sc=new Scanner(System.in);
- int n=sc.nextInt();
- int k=sc.nextInt();
- int cnt=0;
- for(int c=2; c<=n; c++){
- if(!isPrime(c))
- continue;
- for(int i=0; i<primes.length-1; i++){
- int p1=(Integer)primes[i];
- int p2=(Integer)primes[i+1];
- if(c==1+p1+p2){
- cnt++;
- }
- }
- }
- if(cnt>=k)
- System.out.println("YES");
- else
- System.out.println("NO");
- }
- boolean isPrime(int n){
- if(n<=1)
- return false;
- if(n==2)
- return true;
- if(n%2==0)
- return false;
- int m=(int)Math.sqrt(n)+1;
- for(int i=3; i<=m; i+=2)
- if(n%i==0)
- return false;
- return true;
- }
- public static void main(String[] args){
- Locale.setDefault(Locale.US);
- new A().exe();
- }
- }
B Hierarchy
Nickの会社では,n人の従業員を雇用している.
Nickは,従業員の階層構造を作るため,1人を除いたn-1人の従業員に対し,それぞれ1人の監督者を設けることにした.
従業員aiが,従業員biの監督者となる時の費用をciとした時,
ai bi ci
の組がm個与えられる.
階層構造を作ったとき,最小のコストを計算せよ.
実際に木構造を作って階層構造を再現する必要があるかなと思いましたが,そんな必要ありませんでした.
- import java.util.*;
- public class B{
- int n, m;
- int[] q, a, b, c;
- void exe(){
- Scanner sc=new Scanner(System.in);
- n=sc.nextInt();
- q=new int[n];
- for(int i=0; i<n; i++)
- q[i]=sc.nextInt();
- m=sc.nextInt();
- a=new int[m];
- b=new int[m];
- c=new int[m];
- for(int i=0; i<m; i++){
- a[i]=sc.nextInt();
- b[i]=sc.nextInt();
- c[i]=sc.nextInt();
- }
- int max=0;
- for(int i=0; i<n; i++){
- if(q[i]>q[max])
- max=i;
- }
- int cost=0;
- for(int i=0; i<n; i++){
- if(i==max)
- continue;
- int minj=-1;
- for(int j=0; j<m; j++){
- if(b[j]-1==i){
- if(minj==-1||c[j]<c[minj]){
- minj=j;
- }
- }
- }
- if(minj==-1){
- System.out.println("-1");
- return;
- }
- cost+=c[minj];
- }
- System.out.println(""+cost);
- }
- public static void main(String[] args){
- Locale.setDefault(Locale.US);
- new B().exe();
- }
- }
C Balance
文字列が与えられて,ごにょごにょ操作し,ある条件を満たす物は幾つ出来るかといった内容.
組み合わせ問題は苦手ですので,飛ばしました….
\(^o^)/
D Notepad
b進数でn桁の数を,1ページあたりc個書いた時,一番最後のページには幾つの数字が書かれているか?
最終的には,
bn-bn-1 mod c
を求めるという問題に還元出来ましたが,
2≦b<10106, 1≦n<10106, 1≦c<109
という条件に阻まれました.
\(^o^)/
E Palisection
\(^o^)/
・Result
○○×××
D問題が解ければ良かったのですが….
・Rating
0->1580
初挑戦でしたが,無事Div1に昇格する事が出来ました.
0 件のコメント:
コメントを投稿