2014-07-01から1ヶ月間の記事一覧

0046 - Differential

#include <algorithm> #include <iostream> using namespace std; void Slove(void) { double high, max_high=0.0, min_high=10000.0; while (cin >> high) { max_high=max(max_high,high); min_high=min(min_high,high); } cout << max_high-min_high << endl; } int main(void) </iostream></algorithm>…

0045 - Sum and Average

#include <cstdio> #include <iostream> using namespace std; void Slove(void) { int money, number, count=0, sum=0; double average=0.0; while (scanf ("%d,%d", &money, &number) != EOF) { ++count; sum+=money*number; average+=(double)number; } cout << sum << endl</iostream></cstdio>…

0044 - Prime Number II

#include <iostream> using namespace std; #define MAX 100000 bool is_prime[MAX+1]; void Sieve(void) { for (int i=0; i<=MAX; ++i) is_prime[i]=true; is_prime[0]=is_prime[1]=false; for (int i=2; i<=MAX; ++i) if ( is_prime[i] ) for (int j=i*2; j<=MAX; j+</iostream>…

0043 - Puzzle

#include <iostream> #include <string> using namespace std; int Check(int number[]) { int sum=0; for (int i=1; i<10; ++i) sum+=number[i]; return sum; } void dfs(int number[], bool answer_flg[], int i) { if ( !Check(number) ) answer_flg[i]=true; else { for (i</string></iostream>…

0042 - A Thief

#include <cstdio> #include <iostream> using namespace std; int dp[1000+1][1000+1]; int Slove(int W, int number) { int N, value[1000], weight[1000], value_max=0, weight_max=0; cin >> N; for (int i=0; i<=N; ++i) for (int j=0; j<=W; ++j) dp[i][j]=0; for (int i</iostream></cstdio>…

0039 - Roman Figure

#include <iostream> #include <string> using namespace std; int arabia(char rome) { if (rome == 'I') return 1; else if (rome == 'V') return 5; else if (rome == 'X') return 10; else if (rome == 'L') return 50; else if (rome == 'C') return 100; else if (rome =</string></iostream>…

0038 - Poker Hand

#include <algorithm> #include <cstdio> #include <iostream> #include <string> using namespace std; void Slove(int hand[]) { int number_count[13]={0}, answer=0, rank=0; const string pattern[7]={"null", "one pair", "two pair", "three card", "straight", "full house", "four card"}</string></iostream></cstdio></algorithm>…

0036 - A Figure on Surface

#include <iostream> using namespace std; bool Slove(void) { int x=0, y=0; char grid[10][10]; for (int i=0; i<10; ++i) for (int j=0; j<10; ++j) grid[i][j]='0'; for (int i=0; i<8; ++i) for (int j=0; j<8; ++j) cin >> grid[i][j]; if ( cin.eof() ) return</iostream>…

0034 - Railway Lines

#include <cstdio> #include <iostream> using namespace std; void Slove(int l[], int v1, int v2) { int distance=0; for (int i=0; i<10; ++i) distance+=l[i]; double left_collision=(double)distance/(v1+v2)*v1; distance=0; for (int i=0; i<10; ++i) { distance+=l[i</iostream></cstdio>…

0033 - Ball

#include <iostream> using namespace std; bool flg; void dfs(int A[], int B, int C, int count) { if (count == 10) flg=true; else { if (B==0 && C==0) { dfs(A,A[count],C,count+1); dfs(A,B,A[count],count+1); } else { if (A[count] > B) dfs(A,A[count],C,c</iostream>…

0032 - Plastic Board

#include <cstdio> #include <iostream> using namespace std; int rectangle=0, lozenge=0; void Slove(int line1, int line2, int diagonal) { if (diagonal*diagonal == line1*line1+line2*line2) ++rectangle; if (line1 == line2) ++lozenge; } int main(void) { int line</iostream></cstdio>…

0031 - Weight

#include <iostream> #include <vector> using namespace std; void Slove(int weight) { vector<int> answer; answer.clear(); for (int w=(2<<8); w>=1; w/=2) if (w <= weight) { answer.push_back(w); weight-=w; } for (int i=answer.size()-1; i>=0; --i) { cout << answer[i]</int></vector></iostream>…

0030 - Sum of Integers

#include <iostream> using namespace std; int n, s, answer; void dfs(int number, int sum, int count) { if (n==count && s==sum) ++answer; if (number==10 || n==count) return; dfs(number+1,sum,count); dfs(number+1,sum+number,count+1); } void Slove(void)</iostream>…

0029 - English Sentence

#include <algorithm> #include <iostream> #include <map> #include <string> using namespace std; map<string,int> data; bool compare(const pair<string,int> T1, const pair<string,int> T2) { return T1.second < T2.second; } string Slove(string word, string max_length) { if (max_length.size() < word.size()…</string,int></string,int></string,int></string></map></iostream></algorithm>

0028 - Mode Value

#include <algorithm> #include <iostream> using namespace std; int number_count[100]={0}; void Slove(int max_count) { for (int i=0; i<100; ++i) if ( max_count == number_count[i] ) cout << i+1 << endl; } int main(void) { int max_count=0, number; while (cin >> nu</iostream></algorithm>…