2014-09-02から1日間の記事一覧

UVa382 Perfection

UVa

問題 完全数かどうかを判定する問題。AOJ にも AtCoder Beginner Contest にもほぼ同じ問題がある。 #include <cstdio> using namespace std; int main() { int N; puts("PERFECTION OUTPUT"); while(scanf("%d", &N) && N) { printf("%5d ", N); int sum = 0; for(i</cstdio>…

UVa11703 sqrt log sin

UVa

解法 先に計算すべき配列の要素が、どれも i より小さくなるので、順に計算できる。 #include <cstdio> #include <cmath> using namespace std; #define MAX (1000001) #define MOD (1000000) int x[MAX]; int main() { x[0] = 1; for(int i=1; i</cmath></cstdio>

SRM417 Div1Easy(Div2Med) TemplateMatching

SRM

解答 全探索。Sの先頭からとprefixの末尾からの一致と、Sの末尾とsuffixの先頭からの一致をみるループを回せばよい。反省 誤読しまくってやばかった。

UVa11296 Counting Solutions to an Integral Equation

UVa

概要 非負整数 n が与えられる。x. y, z を非負整数として、x+2y+2z = n となるパターン数を求めよ。 ただし n 解答 TLEにならないように一重ループ以内で解きたい。x+Y=n と書き換えると、Y は偶数である必要性が生じる。よって問題文を以下のように解釈し…

UVa11608 No Problem

UVa

概要 問題が足りなくて No problem なのか、問題のストックが十分にあって No problem なのかを出力する。 問題が足りなかった月には一切のコンテストが開かれないので問題は消費しない。その月に作った問題は来月以降にコンテストに出すことが出来る。 #inc…

LiveArchive6465 Islands in the Data Stream

解答 凸が見つかったタイミングで回数をカウントすると良い。 #include <bits/stdc++.h> using namespace std; int main() { int Tc; cin >> Tc; while(Tc--) { int Tcnt; cin >> Tcnt; vector<int> vec(15); for(int i=0; i<15; i++) cin >> vec[i]; int ans = 0; for(int i=0; i</int></bits/stdc++.h>…

UVa11849 CD

UVa

#include <bits/stdc++.h> using namespace std; int main() { int N, M; while(cin >> N >> M && (N|M)) { vector<int> vec(N); for(int i=0; i<N; i++) { cin >> vec[i]; } int sum = 0; for(int i=0; i<M; i++) { int x; cin >> x; sum += binary_search(vec.begin(), vec.end(), x); } cout << sum << endl; } return</m;></n;></int></bits/stdc++.h>…

UVa100 The 3n + 1 problem

UVa

問題概要 n の偶奇で計算を分ける。整数 i と j を含む間の数の中で計算を繰り返した結果 1 になる回数が最大のものを求めて、その回数を出力せよ。解答 UVa の中で最も手を付けられるだろう問題の割にはメモ化再帰しないと恐らく解けない。 奇数の計算をし…

LiveArchive 6468 Pisano Periods

問題 フィボナッチ数列の mod M をとる。数列で出来る周期の長さを求めよ。 フィボナッチ数列が 0 からはじまるものと考えた時、周期ははじめから見て次に 0, 1 が現れるときで区切れる。(部分列の最後が 1, 0 であるともみれる)反省 適当な数値や素数を用…

yukicoder no.21

問題文 http://ch.nicovideo.jp/programing/blomaga/ar612968解答 #include <iostream> #include <cmath> #include <vector> using namespace std; #define allof(c) (c).begin(), (c).end() int main() { int N, K; cin >> N >> K; vector<int> ns(N); for(int i=0; i<N; i++) cin >> ns[i]; cout << *ma</n;></int></vector></cmath></iostream>…