标签:style blog http color io os ar for sp
A
#include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <stack> #include <queue> #include <cctype> #include <cstdio> #include <string> #include <vector> #include <climits> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> #define LL long long #define PI 3.1415926535897932626 using namespace std; int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);} int main() { int a,b,c; while (cin>>a>>b>>c) { int src[100]; src[0] = a + b * c; src[1] = a * b * c; src[2] = (a + b) * c; src[3] = a * b + c; src[4] = a * (b + c); src[5] = a + b + c; sort(src,src+6); printf("%d\n",src[5]); } return 0; }
B
#include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <stack> #include <queue> #include <cctype> #include <cstdio> #include <string> #include <vector> #include <climits> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> #define LL long long #define PI 3.1415926535897932626 using namespace std; int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);} int N,K; #define MAXN 120 struct node { int id,val; friend bool operator < (const node & a,const node &b) { return a.val < b.val; } }src[MAXN]; priority_queue<node>q; node res[120]; int x[1010],y[1010]; int main() { while (scanf("%d%d",&N,&K) != EOF) { int l = 100000,r = 0; for (int i = 0 ;i < N ;i++) { scanf("%d",&src[i].val); src[i].id = i + 1; l = min(l,src[i].val); r = max(r,src[i].val); q.push(src[i]); } if (l == r) {puts("0 0");continue;} node u,s; int cur ,pre = 250000; int anscnt = 0; for (int i = 1; i <= K; i++) { if (cur == 0) break; l = 100000; r = 0; u = q.top();q.pop();int cas = 0; res[cas++] = u; while (true) { s = q.top();q.pop(); res[cas++] = s; if (q.empty()) break; } //for (int i = 0 ;i < cas; i++) printf("%d %d\n",res[i].val,res[i].id);puts(""); res[0].val--; res[cas - 1].val++; anscnt++; x[anscnt] = res[0].id; y[anscnt] = res[cas - 1].id; for (int i = 0 ; i < cas; i++) { q.push(res[i]); l = min(l,res[i].val); r = max(r,res[i].val); } cur = r - l; } printf("%d %d\n",cur,anscnt); for (int i = 1; i <= anscnt; i++) printf("%d %d\n",x[i],y[i]); } return 0; }
C
#include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <stack> #include <queue> #include <cctype> #include <cstdio> #include <string> #include <vector> #include <climits> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> #define LL long long #define PI 3.1415926535897932626 using namespace std; int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);} #define MAXN 5005 int N; struct node { int a,b; friend bool operator < (const node & s,const node & t) { if (s.a == t.a) return s.b < t.b; return s.a < t.a; } }src[MAXN]; int cmp(const node &s,const node &t) { return s.b < t.b; } int main() { scanf("%d",&N); for (int i = 0;i < N ;i++) scanf("%d%d",&src[i].a,&src[i].b); sort(src,src + N); //for (int i = 0 ;i < N; i++) printf("%d %d \n",src[i].a,src[i].b); bool flag = true; for (int i = 1; i < N; i++) if (src[i].b < src[i-1].b) {flag = false ; break;} if (flag) { printf("%d\n",src[N - 1].b);return 0;} printf("%d\n",src[N - 1].a); return 0; }
D
#include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <stack> #include <queue> #include <cctype> #include <cstdio> #include <string> #include <vector> #include <climits> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> #define LL long long #define PI 3.1415926535897932626 using namespace std; int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);} int t[1000005]; set<int>s; int main() { int N,L,x,y; cin >> N >> L >> x >> y; bool fx = false , fy = false; for (int i = 1; i <= N; i++) { cin >> t[i]; s.insert(t[i]); } for (int i = 1; i <= N; i++) { if (s.find(t[i] + x) != s.end()) fx = true; if (s.find(t[i] + y) != s.end()) fy = true; } if (fx && fy) { puts("0");return 0;} if (fx) { printf("1\n"); printf("%d\n",y); return 0; } if (fy) { printf("1\n"); printf("%d\n",x); return 0; } for (int i = 1; i <= N; i++) { if (t[i] + x <= L && ( s.find(t[i] + x + y) != s.end() || (s.find(t[i] + x - y) != s.end()))) { printf("1\n"); printf("%d\n",t[i] + x); return 0; } if (t[i] - x >= 0 && (s.find(t[i] - x + y) != s.end() || s.find(t[i] - x - y) != s.end())) { printf("1\n"); printf("%d\n",t[i] - x); return 0; } } printf("2\n%d %d\n",x,y); return 0; }
E
#include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <stack> #include <queue> #include <cctype> #include <cstdio> #include <string> #include <vector> #include <climits> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> #define LL long long #define PI 3.1415926535897932626 using namespace std; int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);} #define MAXN 5010 #define MOD 1000000007 LL dp[2][MAXN],sum[2][MAXN]; int N,A,B,K; int main() { while (scanf("%d%d%d%d",&N,&A,&B,&K) != EOF) { memset(dp,0,sizeof(dp)); memset(sum,0,sizeof(sum)); dp[0][A] = 1; for (int i = A; i <= N; i++) sum[0][i] = 1; int now = 0; for (int i = 1; i <= K; i++) { now ^= 1; memset(dp[now],0,sizeof(dp[now])); memset(sum[now],0,sizeof(sum[now])); for (int j = 1; j <= N; j++) { if (j < B) { if ((j + B) % 2 == 0) { int k = (j + B) / 2 - 1; dp[now][j] = (dp[now][j] + sum[now ^ 1][k] - dp[now ^ 1][j]) % MOD; } else { int k = (j + B) / 2; dp[now][j] = (dp[now][j] + sum[now ^ 1][k] - dp[now ^ 1][j]) % MOD; } } else if (j > B) { if ((j + B) % 2 == 0) { int k =(j + B) / 2 + 1; dp[now][j] = (dp[now][j] + sum[now ^ 1][N] - sum[now ^ 1][k - 1] -dp[now ^ 1][j]) % MOD; } else { int k = (j + B) / 2 + 1; dp[now][j] = (dp[now][j] + sum[now ^ 1][N] - sum[now ^ 1][k - 1] -dp[now ^ 1][j]) % MOD; } } sum[now][j] = (sum[now][j - 1] + dp[now][j]) % MOD; } } LL ans = 0; for (int i = 1; i <= N; i++) ans = (ans + dp[now][i]) % MOD; printf("%I64d\n",(ans + MOD) % MOD); } return 0; }
标签:style blog http color io os ar for sp
原文地址:http://www.cnblogs.com/Commence/p/4039266.html