A.
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; int n; int main() { freopen("ate.in", "r", stdin); freopen("ate.out", "w", stdout); while(~scanf("%d", &n)) { int ans = 0; for(int i = 1; i < 100; i++) for(int j = 1; j < 100; j++) if(n == i + j) ans++; printf("%d\n", ans); } return 0; }
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define N 5000 + 10 int m, n, a, b; char s[N]; int main() { freopen("black.in", "r", stdin); freopen("black.out", "w", stdout); while(~scanf("%d%d%d%d", &m, &n, &a, &b)) { int cn1 = 0, cn2 = 0; int flag = 0; scanf("%s", s + 1); int len = strlen(s + 1); for(int i = 1; i <= len; i++) { //cout << i << " : " << cn1 << " " << cn2 << endl; if(s[i] == '*') { cn1++; if(!cn2) cn2 = 1; else { if(s[i - 1] != '*') flag = 3; else cn2++; } } } //cout << cn1 << " : " << cn2 << endl; if(cn1 != cn2) flag = 3; if(flag == 3) { printf("Impossible\n"); continue; } if(cn2 == 0) { if((a <= b - 1 && a <= m - b) || (b - 1 >= (a + 1)) || (m - b >= a + 1) || (a == b - 1 && n > a) || (a == m - b && n > a)) flag = 2; else if(a <= b - 1 || a <= m - b) flag = 1; else flag = 3; //cout << flag << endl; } else if(cn2 != a) flag = 3; else { if(b == 1 || b == m || a == 1 || a == m) flag = 1; else flag = 2; } if(flag == 1) { printf("Unique\n"); continue; } if(flag == 2) { printf("Ambiguous\n"); continue; } if(flag == 3) { printf("Impossible\n"); } } return 0; } /* 4 4 4 2 .*** 4 4 2 1 **.* 4 4 2 2 .**. 4 4 3 2 .*.* 4 4 1 2 ..*. 4 4 2 2 ..** 4 4 3 2 .*.* */
#include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <vector> using namespace std; typedef pair<int, int> PII; const int MAXN = 1000 + 10; struct Node { int val, id; }; Node a[MAXN]; vector<int> vec[MAXN]; int n; bool cmp1( const Node &a, const Node &b ) { return a.val < b.val; } int main() { freopen( "dice.in", "r", stdin ); freopen( "dice.out", "w", stdout ); double ans = 0; int tot = 0; scanf( "%d", &n ); for( int i = 0; i < n; ++i ) { scanf( "%d", &a[i].val ); a[i].id = i; tot += a[i].val; } sort( a, a + n, cmp1 ); for( int i = 0; i < n; ++i ) { int id = a[i].id; int sum = 0; for( int j = 0; j < a[i].val; ++j ) { vec[id].push_back( tot ); sum += tot; --tot; } ans += 1.0 * sum / a[i].val; } printf( "%.5f\n", ans ); for( int i = 0; i < n; ++i ) { sort( vec[i].begin(), vec[i].end() ); printf( "%d", vec[i][0] ); for( int j = 1; j < vec[i].size(); ++j ) { printf( " %d", vec[i][j] ); } puts( "" ); } return 0; }
#include <iostream> #include <cstring> #include <cstdio> using namespace std; const int MAXN = 1000 + 10; int n, c, a; int val[MAXN]; char t[MAXN]; int main() { freopen( "flat.in", "r", stdin ); freopen( "flat.out", "w", stdout ); int tot = 0; val[0] = val[1] = val[2] = 0; scanf( "%d%d", &n, &c ); for( int i = 0; i < n; ++i ) { scanf( "%d%s", &a, t ); if( t[0] == 'b' && t[1] == 'a' && t[2] == 'l' ) val[2] += a; if( t[0] == 'b' && t[1] == 'e' ) val[1] += a; else val[0] += a; tot += a; } printf( "%d\n", tot ); printf( "%d\n", val[1] ); printf( "%lf\n", ( 1.0 * tot - 1.0 * val[2] / 2.0 ) * c ); return 0; }J.
#include <algorithm> #include <iostream> #include <cstdio> using namespace std; const int INF = 0x3FFFFFFF; const int MAXN = 100000 + 10; struct Node { int a, b; bool operator < ( const Node &t ) const { return a == t.a ? b < t.b : a < t.a; } }; Node node[MAXN]; int L[MAXN], R[MAXN], a[MAXN]; long long cnt; void _merge( int l, int m, int r ) { int i, j, k; int n1, n2; n1 = m - l + 1; n2 = r - m; for( i = 0; i < n1; ++i ) L[i] = a[l + i]; for( i = 0; i < n2; ++i ) R[i] = a[m + 1 + i]; L[n1] = INF; R[n2] = INF; i = j = 0; for( k = l; k <= r; ++k ) { if( L[i] <= R[j] ) a[k] = L[i++]; else { a[k] = R[j++]; cnt += n1 - i; } } return ; } void _merge_sort( int l, int r ) { if( l < r ) { int m = ( l + r ) / 2; _merge_sort( l, m ); _merge_sort( m + 1, r ); _merge( l, m, r ); } return ; } int main() { freopen( "john.in", "r", stdin ); freopen( "john.out", "w", stdout ); int n; scanf( "%d", &n ); // while( ~scanf( "%d", &n ) && n ) { for( int i = 0; i < n; ++i ) { scanf( "%d%d", &node[i].a, &node[i].b ); } sort( node, node + n ); cnt = 0; for( int i = 0; i < n; ++i ) a[i] = node[i].b; _merge_sort( 0, n - 1 ); printf( "%I64d\n", cnt ); // } return 0; }