
1 #include<iostream> 2 #include<iomanip> 3 using namespace std; 4 5 const double PI = 3.1415927; 6 int main() 7 { 8 double r; 9 while(cin >> r) 10 { 11 cout.precision(3); 12 cout.setf(ios::fixed); 13 cout << 4*PI*r*r*r/3 << endl; 14 } 15 return 0; 16 }

1 #include<iostream> 2 #include<iomanip> 3 #include<cmath> 4 #include<cstdlib> 5 using namespace std; 6 7 class P 8 { 9 public: 10 double x; 11 double y; 12 friend istream& operator>>(istream& in, P& p); 13 }; 14 inline istream& operator>>(istream& in, P& p) 15 { 16 in >> p.x >> p.y; 17 return in; 18 } 19 20 double dist(P a, P b) 21 { 22 return hypot(a.x - b.x,a.y-b.y); 23 } 24 int main() 25 { 26 P a, b; 27 while(cin >> a >> b) 28 { 29 cout.precision(2); 30 cout.setf(ios::fixed); 31 cout << dist(a, b) << endl; 32 } 33 return 0; 34 }

1 #include<iostream> 2 #include<iomanip> 3 using namespace std; 4 5 const double PI = 3.1415927; 6 int main() 7 { 8 double r; 9 while(cin >> r) 10 { 11 cout.precision(3); 12 cout.setf(ios::fixed); 13 cout << 4*PI*r*r*r/3 << endl; 14 } 15 return 0; 16 }

1 #include<iostream> 2 #include<cmath> 3 #include<iomanip> 4 using namespace std; 5 6 int main() 7 { 8 double s; 9 while(cin >> s) 10 { 11 cout.precision(2); 12 cout.setf(ios::fixed); 13 cout << fabs(s) << endl; 14 } 15 return 0; 16 }

1 #include<iostream> 2 #include<string> 3 using namespace std; 4 5 string judge(int x) 6 { 7 if(x >= 0 && x <= 100) 8 { 9 10 if(x >= 90) 11 return "A"; 12 else if(x >= 80) 13 return "B"; 14 else if(x >= 70) 15 return "C"; 16 else if(x >= 60) 17 return "D"; 18 else if(x >= 0) 19 return "E"; 20 } 21 else 22 return "Score is error!"; 23 } 24 int main() 25 { 26 int x; 27 while(cin >> x) 28 { 29 cout << judge(x) << endl; 30 } 31 return 0; 32 }

1 #include<iostream> 2 #include<string> 3 #include<sstream> 4 #include<vector> 5 using namespace std; 6 7 int fate[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 8 bool judge(int year) 9 { 10 if(year%4 == 0 && year%100 != 0 || year % 400 == 0) 11 return true; 12 return false; 13 } 14 int get(string date) 15 { 16 stringstream stream(date); 17 int year, month, day; 18 char c; 19 stream >> year >> c >> month >> c >> day; 20 int days = day; 21 for(int i = 1; i < month; ++i) 22 { 23 days += fate[i]; 24 if(i == 2 && judge(year)) 25 days += 1; 26 } 27 return days; 28 } 29 int main() 30 { 31 string date; 32 while(cin >> date) 33 { 34 cout << get(date) << endl; 35 } 36 return 0; 37 }

1 #include<iostream> 2 using namespace std; 3 4 int main() 5 { 6 int n, x; 7 while(cin >> n) 8 { 9 int fac = 1; 10 while(n--) 11 { 12 cin >> x; 13 if(x % 2) 14 fac *= x; 15 } 16 cout << fac << endl; 17 } 18 return 0; 19 }

1 #include<iostream> 2 using namespace std; 3 4 int main() 5 { 6 int x, y; 7 while(cin >> x >> y) 8 { 9 if(x > y) 10 { 11 int t = x; 12 x = y; 13 y = t; 14 } 15 int fac1 = 0, fac2 = 0; 16 for(; x <= y; ++x) 17 { 18 if(x % 2) 19 fac2 += x*x*x; 20 else 21 fac1 += x*x; 22 } 23 cout << fac1 << " " << fac2 << endl; 24 } 25 return 0; 26 }

1 #include<iostream> 2 using namespace std; 3 4 int main() 5 { 6 int n; 7 while(cin >> n, n != 0) 8 { 9 double x; 10 int a = 0, b = 0, c = 0; 11 while(n--) 12 { 13 cin >> x; 14 if(x < 0) 15 a++; 16 else if (x > 0) 17 c++; 18 else 19 b++; 20 } 21 cout << a << " " << b << " " << c << endl; 22 } 23 return 0; 24 }

1 #include<iostream> 2 #include<cmath> 3 #include<iomanip> 4 using namespace std; 5 6 int main() 7 { 8 int m; 9 double n; 10 while(cin >> n >> m) 11 { 12 double sum = 0; 13 for(int i = 0; i < m; ++i) 14 { 15 sum += n; 16 n = sqrt(n); 17 } 18 cout.precision(2); 19 cout.setf(ios::fixed); 20 cout << sum << endl; 21 } 22 return 0; 23 }

1 #include<iostream> 2 #include<cmath> 3 using namespace std; 4 5 bool is_narcissistic(int x) 6 { 7 int units, decade, hundreds; 8 units = x % 10; 9 decade = (x/10)%10; 10 hundreds= x/100; 11 if(pow(units, 3) + pow(decade, 3) + pow(hundreds, 3) == x) 12 return true; 13 return false; 14 } 15 int main() 16 { 17 int m, n; 18 while(cin >> m >> n) 19 { 20 bool flag = false; 21 for(int i = m; i <= n; ++i) 22 if(is_narcissistic(i)) 23 { 24 if(flag == false) 25 cout << i; 26 else 27 cout << " " << i; 28 flag = true; 29 } 30 if(flag == false) 31 cout << "no"; 32 cout << endl; 33 } 34 return 0; 35 }

1 #include<iostream> 2 #include<iomanip> 3 using namespace std; 4 5 int main() 6 { 7 int m, x; 8 cin >> m; 9 while(m--) 10 { 11 cin >> x; 12 double sum = 1; 13 int flag = -1; 14 for(int i = 2; i <= x; ++i) 15 { 16 sum += 1.0*flag/i; 17 flag = -flag; 18 } 19 cout.precision(2); 20 cout.setf(ios::fixed); 21 cout << sum << endl; 22 } 23 return 0; 24 }

1 #include<iostream> 2 #include<cassert> 3 #include<cmath> 4 using namespace std; 5 6 int f(int x) 7 { 8 return x*x+x+41; 9 } 10 bool is_prime(int x) 11 { 12 assert(x >= 0);//检查非法参数并给出提示信息 13 if(x == 1) 14 return false; 15 int t = floor(sqrt((double)x)+0.5);//避免浮点误差(避免误差.99999被截掉) 16 for(int i = 2; i <= t; ++i) 17 if(x % i == 0) 18 return false; 19 return true; 20 } 21 int main() 22 { 23 int x, y; 24 while(cin >> x >> y, x != 0 || y != 0) 25 { 26 int start = f(x), end = f(y); 27 bool flag = true; 28 for(int i = x; i <= y; ++i) 29 { 30 if(!is_prime(f(i))) 31 { 32 flag = false; 33 break; 34 } 35 } 36 if(flag == true) 37 cout << "OK" << endl; 38 else 39 cout << "Sorry" << endl; 40 } 41 return 0; 42 }

1 #include<iostream> 2 using namespace std; 3 4 int main() 5 { 6 int n; 7 while(cin >> n) 8 { 9 int sum = 1; 10 for(int i = n-1; i > 0; --i) 11 { 12 sum = (sum + 1)*2; 13 } 14 cout << sum << endl; 15 } 16 return 0; 17 }

1 #include<iostream> 2 #include<vector> 3 #include<algorithm> 4 #include<iomanip> 5 using namespace std; 6 7 int main() 8 { 9 int n; 10 while(cin >> n) 11 { 12 double x; 13 vector<double> vec; 14 while(n--) 15 { 16 cin >> x; 17 vec.push_back(x); 18 } 19 sort(vec.begin(), vec.end()); 20 double sum = 0; 21 for(int i = 1; i < vec.size()-1; ++i) 22 sum += vec[i]; 23 cout.precision(2); 24 cout.setf(ios::fixed); 25 cout << sum/(vec.size()-2) << endl; 26 } 27 return 0; 28 }

1 #include<iostream> 2 using namespace std; 3 4 int main() 5 { 6 int n, m; 7 while(cin >> n >> m) 8 { 9 int a = 0; 10 for(int i = 1; i <= n / m; ++i) 11 { 12 a = 2*((i-1)*m+1); 13 if(i != 1) 14 cout << " "; 15 cout << a+m-1; 16 } 17 if(n%m != 0) 18 { 19 if(n/m != 0) 20 cout << " "; 21 a = 2*((n/m)*m+1); 22 m = n % m; 23 cout << a+m-1; 24 } 25 cout << endl; 26 } 27 return 0; 28 }

1 #include<iostream> 2 #include<vector> 3 using namespace std; 4 5 int main() 6 { 7 int n; 8 while(cin >> n, n!=0) 9 { 10 int min = 0, x; 11 vector<int> vec; 12 for(int i = 0; i < n; ++i) 13 { 14 cin >> x; 15 vec.push_back(x); 16 if(vec[min] > vec[i]) 17 min = i; 18 } 19 int t = vec[0]; 20 vec[0] = vec[min]; 21 vec[min] = t; 22 for(int i = 0; i < n; i++) 23 { 24 cout << vec[i]; 25 if(i != n-1) 26 cout << " "; 27 } 28 cout << endl; 29 } 30 return 0; 31 }

1 #include<iostream> 2 #include<string> 3 using namespace std; 4 5 int main() 6 { 7 int n; 8 string str; 9 cin >> n; 10 while(n--) 11 { 12 cin >> str; 13 int sum = 0; 14 for(int i = 0; i != str.size(); ++i) 15 if(str[i] >= '0' && str[i] <= '9') 16 ++sum; 17 cout << sum << endl; 18 } 19 return 0; 20 }

1 #include<iostream> 2 using namespace std; 3 4 const int maxn = 50+5; 5 int a[maxn] = {0,1,2,3}; 6 int main() 7 { 8 int n; 9 for(int i = 4; i <= maxn; ++i) 10 a[i] = a[i-1]+a[i-3]; 11 while(cin >> n, n!=0) 12 { 13 cout << a[n] << endl; 14 } 15 return 0; 16 }
分析:增量图

1 #include<iostream> 2 #include<vector> 3 using namespace std; 4 5 const int maxn = 100+10; 6 int main() 7 { 8 int n, m, x; 9 vector<int> vec(maxn, 0); 10 while(cin >> n >> m, n !=0||m!=0) 11 { 12 for(int i = 0; i < n; i++) 13 { 14 cin >> x; 15 //vec.push_back(x); 16 vec[i] = x; 17 } 18 for(int i = n-1; i >= 0; i--) 19 { 20 if(vec[i] > m) 21 vec[i+1] = vec[i]; 22 else 23 { 24 vec[i+1] = m; 25 break; 26 } 27 } 28 for(int i = 0; i != n+1; i++) 29 { 30 cout << vec[i]; 31 if(i != n) 32 cout << " "; 33 } 34 cout << endl; 35 } 36 return 0; 37 }

1 #include<iostream> 2 #include<vector> 3 #include<algorithm> 4 #include<cmath> 5 using namespace std; 6 7 bool compare(int a, int b) 8 { 9 return abs(a)>abs(b); 10 } 11 int main() 12 { 13 int n, x; 14 while(cin >> n, n !=0) 15 { 16 vector<int> vec; 17 for(int i = 0; i < n; i++) 18 { 19 cin >> x; 20 vec.push_back(x); 21 } 22 sort(vec.begin(), vec.end(), compare); 23 for(int i = 0; i < n; i++) 24 { 25 if(i != 0) 26 cout << " "; 27 cout << vec[i]; 28 } 29 cout << endl; 30 } 31 return 0; 32 }

1 #include<iostream> 2 using namespace std; 3 4 const int maxn = 6; 5 const int a[maxn] = {100,50,10,5,2,1}; 6 7 int get(int x) 8 { 9 int sum = 0; 10 for(int i = 0; i < maxn; i++) 11 { 12 if(x/a[i] != 0) 13 { 14 sum += x/a[i]; 15 x = x%a[i]; 16 } 17 } 18 return sum; 19 } 20 int main() 21 { 22 int n, x; 23 while(cin >> n, n!=0) 24 { 25 int sum = 0; 26 for(int i = 0; i < n; ++i) 27 { 28 cin >> x; 29 sum += get(x); 30 } 31 cout << sum << endl; 32 } 33 return 0; 34 }

1 #include<iostream> 2 #include<cstdlib> 3 using namespace std; 4 5 int main() 6 { 7 int m, n; 8 while(cin >> m >> n) 9 { 10 int x, score, row = 1, column = 1; 11 for(int i = 1; i <= m; ++i) 12 { 13 for(int j = 1; j <= n; ++j) 14 { 15 cin >> x; 16 if(i == 1 && j == 1) 17 { 18 score = x; 19 continue; 20 } 21 if(abs(score) < abs(x)) 22 { 23 score = x; 24 row = i; 25 column = j; 26 } 27 } 28 } 29 cout << row << " " << column << " " << score << endl; 30 } 31 return 0; 32 }

1 #include<iostream> 2 #include<iomanip> 3 using namespace std; 4 5 const int row = 50 + 5; 6 const int column = 5 + 5; 7 8 void out(double a[], int n) 9 { 10 for(int i = 0; i < n; ++i) 11 { 12 cout << a[i]; 13 if(i != n-1) 14 cout << " "; 15 } 16 cout << endl; 17 } 18 int main() 19 { 20 int m, n, a[row][column]; 21 cout.precision(2); 22 cout.setf(ios::fixed); 23 while(cin >> n >> m) 24 { 25 double stu[row] = {0}, cl[column] = {0}; 26 for(int i = 0; i < n; ++i) 27 { 28 for(int j = 0; j < m; ++j) 29 { 30 cin >> a[i][j]; 31 stu[i] += a[i][j]; 32 } 33 stu[i] /= m; 34 } 35 for(int j = 0; j < m; ++j) 36 { 37 for(int i = 0; i < n; ++i) 38 cl[j] += a[i][j]; 39 cl[j] /= n; 40 } 41 out(stu, n); 42 out(cl, m); 43 int sum = 0; 44 for(int i = 0; i < n; ++i) 45 { 46 bool flag = true; 47 for(int j = 0; j < m; ++j) 48 if(a[i][j] < cl[j]) 49 flag = false; 50 if(flag) 51 ++sum; 52 } 53 cout << sum << endl << endl; 54 } 55 return 0; 56 }

1 #include<iostream> 2 #include<string> 3 #include<cctype> 4 using namespace std; 5 6 int main() 7 { 8 int n; 9 cin >> n; 10 cin.ignore(); 11 while(n--) 12 { 13 string str; 14 getline(cin, str); 15 bool flag = true; 16 if(isalpha(str[0]) || str[0] == '_') 17 { 18 for(int i = 1; i != str.size(); ++i) 19 if(!isalpha(str[i]) && !isdigit(str[i]) && str[i] != '_') 20 { 21 flag = false; 22 break; 23 } 24 } 25 else 26 flag = false; 27 if(flag) 28 cout << "yes" << endl; 29 else 30 cout << "no" << endl; 31 } 32 return 0; 33 }

1 #include<iostream> 2 #include<string> 3 using namespace std; 4 5 int get(string str) 6 { 7 char max = str[0]; 8 int sub = 0; 9 for(int i = 1; i != str.size(); ++i) 10 { 11 if(str[i] > max) 12 { 13 sub = i; 14 max = str[i]; 15 } 16 } 17 return sub; 18 } 19 int main() 20 { 21 string str; 22 while(cin >> str) 23 { 24 for(int i = 0; i != str.size(); ++i) 25 { 26 cout << str[i]; 27 if(str[i] == str[get(str)]) 28 cout << "(max)"; 29 } 30 cout << endl; 31 } 32 return 0; 33 }

1 #include<iostream> 2 #include<string> 3 #include<cctype> 4 using namespace std; 5 6 int main() 7 { 8 string str; 9 while(getline(cin, str)) 10 { 11 bool flag = true; 12 for(int i = 0; i != str.size(); ++i) 13 { 14 if(flag) 15 { 16 str[i] = toupper(str[i]); 17 flag = false; 18 } 19 if(str[i] == ' ') 20 flag = true; 21 } 22 cout << str << endl; 23 } 24 return 0; 25 }

1 #include<iostream> 2 #include<string> 3 #include<cctype> 4 using namespace std; 5 6 #define P(a) \ 7 cout << #a ":" << a << endl; 8 int main() 9 { 10 int n; 11 cin >> n; 12 cin.ignore(); 13 while(n--) 14 { 15 string str; 16 getline(cin, str); 17 int a = 0, e = 0, i = 0, o = 0, u = 0; 18 for(int j = 0; j != str.size(); ++j) 19 { 20 if(toupper(str[j]) == 'A') 21 ++a; 22 else if(toupper(str[j]) == 'E') 23 ++e; 24 else if(toupper(str[j]) == 'I') 25 ++i; 26 else if(toupper(str[j]) == 'O') 27 ++o; 28 else if(toupper(str[j]) == 'U') 29 ++u; 30 } 31 P(a); 32 P(e); 33 P(i); 34 P(o); 35 P(u); 36 if(n) 37 cout << endl; 38 } 39 return 0; 40 }
2028:Lowest Common Multiple Plus

1 #include<iostream> 2 using namespace std; 3 4 int f(int a, int b) 5 { 6 int m = a, n = b; 7 if(a < b) 8 { 9 int t = a; 10 a = b; 11 b = t; 12 } 13 while(b) 14 { 15 int t = b; 16 b = a % b; 17 a = t; 18 } 19 return m*(n/a); 20 } 21 int main() 22 { 23 int n; 24 while(cin >> n) 25 { 26 int a, b; 27 cin >> a; 28 for(int i = 1; i < n; ++i) 29 { 30 cin >> b; 31 a = f(a, b); 32 } 33 cout << a << endl; 34 } 35 return 0; 36 }
2029: Palindromes _easy version

1 #include<iostream> 2 #include<string> 3 using namespace std; 4 5 bool judge(string str) 6 { 7 int len = str.size(); 8 for(int i = 0; i <= len/2; ++i) 9 { 10 if(str[i] != str[len-i-1]) 11 return false; 12 } 13 return true; 14 } 15 int main() 16 { 17 int n; 18 cin >> n; 19 cin.ignore(); 20 while(n--) 21 { 22 string str; 23 getline(cin, str); 24 if(judge(str)) 25 cout << "yes" << endl; 26 else 27 cout << "no" << endl; 28 } 29 return 0; 30 }

1 #include<iostream> 2 #include<string> 3 using namespace std; 4 5 int get(string str) 6 { 7 int num = 0; 8 for(int i = 0; i != str.size(); ++i) 9 if(str[i] < 0) 10 ++num; 11 return num/2; 12 } 13 int main() 14 { 15 int n; 16 cin >> n; 17 cin.ignore(); 18 while(n--) 19 { 20 string str; 21 getline(cin, str); 22 cout << get(str) << endl; 23 } 24 return 0; 25 }

1 #include<iostream> 2 #include<vector> 3 using namespace std; 4 5 void get(int n, int r, vector<int> & ivec) 6 { 7 if(n < 0) 8 n = -n; 9 while(n / r != 0) 10 { 11 ivec.push_back(n%r); 12 n /= r; 13 } 14 ivec.push_back(n%r); 15 } 16 void out(int n, vector<int> &ivec) 17 { 18 if(n < 0) 19 cout << "-"; 20 for(int i = ivec.size()-1; i >= 0; --i) 21 { 22 if(ivec[i] > 9) 23 cout << (char)(ivec[i]+55); 24 else 25 cout << ivec[i]; 26 } 27 } 28 int main() 29 { 30 int n, r; 31 while(cin >> n >> r) 32 { 33 vector<int> ivec; 34 get(n, r, ivec); 35 out(n, ivec); 36 cout << endl; 37 } 38 return 0; 39 }

1 #include<iostream> 2 #include<cstdlib> 3 using namespace std; 4 5 const int maxn = 30 + 5; 6 int a[maxn][maxn] = {0}; 7 int main() 8 { 9 int n; 10 //memset(a, 0, sizeof(a)); 11 for(int i = 0; i < maxn; ++i) 12 a[i][0] = 1; 13 for(int i = 1; i < maxn; ++i) 14 for(int j = 1; j <= i; ++j) 15 { 16 a[i][j] = a[i-1][j] + a[i-1][j-1]; 17 } 18 while(cin >> n) 19 { 20 for(int i = 0; i < n; ++i) 21 { 22 for(int j = 0; j <= i; ++j) 23 { 24 if(j) 25 cout << " "; 26 cout << a[i][j]; 27 } 28 cout << endl; 29 } 30 cout << endl; 31 } 32 return 0; 33 }

1 #include<iostream> 2 using namespace std; 3 4 class Time 5 { 6 public: 7 int hour; 8 int minute; 9 int second; 10 friend istream& operator>>(istream& in, Time& t); 11 friend ostream& operator<<(ostream& out, Time& t); 12 Time& operator+=(const Time& t); 13 }; 14 inline istream& operator>>(istream& in, Time& t) 15 { 16 in >> t.hour >> t.minute >> t.second; 17 return in; 18 } 19 inline ostream& operator<<(ostream& out, Time& t) 20 { 21 out << t.hour << " " << t.minute << " " << t.second; 22 return out; 23 } 24 inline Time& Time::operator+=(const Time& t) 25 { 26 second += t.second; 27 if(second >= 60) 28 { 29 minute += second / 60; 30 second %= 60; 31 } 32 minute += t.minute; 33 if(minute >= 60) 34 { 35 hour += minute / 60; 36 minute %= 60; 37 } 38 hour += t.hour; 39 return *this; 40 } 41 inline Time& operator+(const Time& t1, const Time& t2) 42 { 43 Time t(t1); 44 t += t2; 45 return t; 46 } 47 int main() 48 { 49 int n; 50 cin >> n; 51 while(n--) 52 { 53 Time t1, t2; 54 cin >> t1 >> t2; 55 cout << t1+t2 << endl; 56 } 57 return 0; 58 }

#include<iostream> #include<vector> #include<algorithm> using namespace std; void get(vector<int> A, vector<int> B, vector<int>& C) { int i = 0, j = 0; while(i != A.size() && j != B.size()) { if(A[i] < B [j]) { C.push_back(A[i]); ++i; } else if(A[i] == B[j]) { ++i; ++j; } else { ++j; } } while(i != A.size()) { C.push_back(A[i]); ++i; } } void out(vector<int> C) { if(C.size() == 0) cout << "NULL"; else for(int i = 0; i != C.size(); ++i) cout << C[i] << " "; } int main() { int n, m; while(cin >> n >> m, n != 0 || m != 0) { vector<int> A; int x; for(int i = 0; i < n; ++i) { cin >> x; A.push_back(x); } sort(A.begin(), A.end()); vector<int> B; for(int i = 0; i < m; ++i) { cin >> x; B.push_back(x); } sort(B.begin(), B.end()); vector<int> C; get(A, B, C); out(C); cout << endl; } return 0; }

1 #include<iostream> 2 using namespace std; 3 4 int main() 5 { 6 int a, b; 7 while(cin >> a >> b, a != 0 && b != 0) 8 { 9 const int ge = a % 10; 10 const int shi = (a/10)%10; 11 const int bai = a / 100; 12 int ge1 = ge, shi1 = shi, bai1 = bai; 13 for(int i = 1; i < b; ++i) 14 {//注意此处的顺序,很重要 15 bai1 = ge*bai1 + shi*shi1 + bai*ge1; 16 shi1 = ge*shi1 + shi*ge1; 17 ge1 = ge*ge1; 18 shi1 += ge1 / 10; 19 ge1 %= 10; 20 bai1 += shi1 / 10; 21 shi1 %= 10; 22 bai1 %= 10; 23 } 24 cout << ge1 + shi1*10 + bai1*100 << endl; 25 } 26 return 0; 27 }

1 #include<iostream> 2 #include<vector> 3 #include<cstdlib> 4 #include<iomanip> 5 using namespace std; 6 7 class P 8 { 9 public: 10 double x; 11 double y; 12 friend istream& operator>>(istream& in, P& p); 13 }; 14 inline istream& operator>>(istream& in, P& p) 15 { 16 in >> p.x >> p.y; 17 return in; 18 } 19 20 int main() 21 { 22 int n; 23 while(cin >> n, n != 0) 24 { 25 P x; 26 vector<P> p; 27 for(int i = 0; i < n; ++i) 28 { 29 cin >> x; 30 p.push_back(x); 31 } 32 double area = 0; 33 for(int i = 0, j = 1; i < n; ++i, ++j) 34 { 35 j %= n; 36 area += p[i].x*p[j].y - p[i].y*p[j].x; 37 } 38 area = area*0.5; 39 if(area < 0) 40 area = -area; 41 cout.setf(ios::fixed); 42 cout.precision(1); 43 cout << area << endl; 44 } 45 return 0; 46 }

1 #include<iostream> 2 #include<vector> 3 #include<algorithm> 4 using namespace std; 5 6 class Ti 7 { 8 public: 9 int s, e; 10 friend istream& operator>>(istream& in, Ti& t); 11 }; 12 inline istream& operator>>(istream& in, Ti& t) 13 { 14 in >> t.s >> t.e; 15 return in; 16 } 17 18 bool cmp(const Ti& t1, const Ti& t2) 19 { 20 if(t1.e < t2.e) 21 return true; 22 else if(t1.e == t2.e) 23 return t1.s < t2.s; 24 return false; 25 } 26 void out(vector<Ti>& t) 27 { 28 for(int i = 0; i != t.size(); ++i) 29 cout << t[i].s << " " << t[i].e << endl; 30 } 31 32 int get(vector<Ti> t) 33 { 34 int count = 1, p = t[0].e; 35 for(int i = 1; i != t.size(); ++i) 36 if(t[i].s >= p) 37 { 38 ++count; 39 p = t[i].e; 40 } 41 return count; 42 } 43 int main() 44 { 45 int n; 46 while(cin >> n, n != 0) 47 { 48 Ti x; 49 vector<Ti> t; 50 for(int i = 0; i < n; ++i) 51 { 52 cin >> x; 53 t.push_back(x); 54 } 55 sort(t.begin(), t.end(), cmp); 56 //out(t); 57 cout << get(t) << endl; 58 } 59 return 0; 60 }

1 #include<iostream> 2 using namespace std; 3 4 bool is_true(double a, double b, double c) 5 { 6 if(a + b > c && a + c > b && b + c > a) 7 return true; 8 return false; 9 } 10 int main() 11 { 12 int n; 13 cin >> n; 14 while(n--) 15 { 16 double a, b, c; 17 cin >> a >> b >> c; 18 if(is_true(a, b, c)) 19 cout << "YES"; 20 else 21 cout << "NO"; 22 cout << endl; 23 } 24 return 0; 25 }

1 #include<iostream> 2 using namespace std; 3 4 int f(int a) 5 { 6 int sum = 0; 7 for(int i = 1; i < a; ++i) 8 { 9 if(a % i == 0) 10 sum += i; 11 } 12 return sum; 13 } 14 int main() 15 { 16 int n; 17 cin >> n; 18 while(n--) 19 { 20 int a, b; 21 cin >> a >> b; 22 if(f(a) == b && a == f(b)) 23 cout << "YES"; 24 else 25 cout << "NO"; 26 cout << endl; 27 } 28 return 0; 29 }

1 #include<iostream> 2 using namespace std; 3 4 const int maxn = 40+5; 5 int a[maxn] = {0,0,1,2}; 6 int main() 7 { 8 int n; 9 cin >> n; 10 for(int i = 4; i <= maxn; ++i) 11 a[i] = a[i-1] + a[i-2]; 12 while(n--) 13 { 14 int x; 15 cin >> x; 16 cout << a[x]; 17 cout << endl; 18 } 19 return 0; 20 }

1 #include<iostream> 2 using namespace std; 3 4 const int maxn = 30 + 5; 5 int a[maxn] = {3}; 6 7 int main() 8 { 9 for(int i = 1; i <= maxn; ++i) 10 a[i] = (a[i-1]-1)*2; 11 int n; 12 cin >> n; 13 while(n--) 14 { 15 int x; 16 cin >> x; 17 cout << a[x]; 18 cout << endl; 19 } 20 return 0; 21 }

1 #include<iostream> 2 #include<string> 3 #include<cctype> 4 using namespace std; 5 6 int main() 7 { 8 int n; 9 cin >> n; 10 while(n--) 11 { 12 string str; 13 cin >> str; 14 int a = 0, b = 0, c = 0, d = 0; 15 for(int i = 0; i != str.size(); ++i) 16 { 17 if(str[i] >= 'a' && str[i] <= 'z') 18 a = 1; 19 else if(str[i] >= 'A' && str[i] <= 'Z') 20 b = 1; 21 else if(str[i] >= '0' && str[i] <= '9') 22 c = 1; 23 else if(str[i] == '~' || str[i] == '!' 24 || str[i] == '@' || str[i] == '#' 25 || str[i] == '$' || str[i] == '%' 26 || str[i] == '^') 27 d = 1; 28 } 29 if(str.size() >= 8 && str.size() <= 16 && a+b+c+d >= 3) 30 cout << "YES"; 31 else 32 cout << "NO"; 33 cout << endl; 34 } 35 return 0; 36 }

1 #include<iostream> 2 using namespace std; 3 4 const int maxn = 50+5; 5 __int64 a[maxn] = {0,1,2};//注意数据长度限制 6 7 int main() 8 { 9 for(int i = 2; i <= maxn; ++i) 10 a[i] = a[i-1] + a[i-2] ; 11 int n, i, j; 12 cin >> n; 13 while(n-- && cin >> i >> j) 14 { 15 cout << a[j-i+1] << endl; 16 } 17 return 0; 18 }

1 #include<iostream> 2 using namespace std; 3 const int maxn = 40+5; 4 __int64 s[maxn] = {0,3,8}; 5 int main() 6 { 7 for(int i = 3; i < maxn; ++i) 8 s[i] = 2*(s[i-1] + s[i-2]); 9 int n; 10 while(cin >> n) 11 { 12 cout << s[n] << endl; 13 } 14 return 0; 15 } 16 17 /* 18 如果末尾加的是E或F(总是可以的),显然是2*a(i-1),如果加的是O,则末2位一定是EO或FO,则为2*a(i-2),由加法原理... 19 */

1 #include<iostream> 2 #include<iomanip> 3 using namespace std; 4 const int maxn = 20 + 5; 5 __int64 a[maxn] = {0,0,1}; 6 7 __int64 fact(int x) 8 { 9 __int64 s = 1; 10 for(int i = 2; i <= x; ++i) 11 s *= i; 12 return s; 13 } 14 int main() 15 { 16 for(int i = 3; i < maxn; ++i) 17 a[i] = (i-1)*(a[i-1]+a[i-2]); 18 int n, x; 19 cin >> n; 20 while(n-- && cin >> x) 21 { 22 cout.setf(ios::fixed); 23 cout.precision(2); 24 cout << 100.0*a[x] / fact(x) << '%' << endl; 25 } 26 return 0; 27 }

1 #include<iostream> 2 using namespace std; 3 const int maxn = 20 + 5; 4 __int64 a[maxn] = {0,0,1}; 5 6 __int64 f(int x) 7 { 8 __int64 s = 1; 9 for(int i = 2; i <= x; ++i) 10 s *= i; 11 return s; 12 } 13 int main() 14 { 15 for(int i = 3; i < maxn; ++i) 16 a[i] = (i-1)*(a[i-1] + a[i-2]); 17 int c, n, m; 18 cin >> c; 19 while(c-- && cin >> n >> m) 20 { 21 cout << f(n)/f(m)/f(n-m)*a[m] << endl; 22 } 23 return 0; 24 }

1 #include<iostream> 2 #include<cmath> 3 using namespace std; 4 5 int f(int x) 6 { 7 int count = 1; 8 while(x / 2) 9 { 10 x /= 2; 11 count++; 12 } 13 return count; 14 } 15 int main() 16 { 17 int x; 18 while(cin >> x) 19 { 20 bool flag = false; 21 for(int i = f(x); i >= 0; --i) 22 if(x & (1 << i) ) 23 { 24 flag = true; 25 cout << '1'; 26 } 27 else if(flag) 28 cout << '0'; 29 cout << endl; 30 } 31 return 0; 32 }

1 #include<iostream> 2 using namespace std; 3 4 void p1(int w) 5 { 6 int i = 0; 7 cout << '+' ; 8 while(i < w) 9 { 10 cout << '-' ; 11 ++i; 12 } 13 cout << '+' ; 14 cout << endl; 15 } 16 void p2(int w, int h) 17 { 18 int i = 0; 19 cout << '|' ; 20 while(i < w) 21 { 22 cout << " "; 23 ++i; 24 } 25 cout << '|'; 26 cout << endl; 27 } 28 int main() 29 { 30 int w, h; 31 while(cin >> w >> h) 32 { 33 int j = 0; 34 p1(w); 35 while(j++ < h) 36 p2(w, h); 37 p1(w); 38 cout << endl; 39 } 40 return 0; 41 }