177 条题解
-
-2
竟然没人用高精度#include <iostream> using namespace std; string a , b; int ans[250] , numa[240] , numb[240] , lena , lenb , lenans , top; int main() { cin >> a >> b; lena = a.length(); lenb = b.length(); lenans = max(lena , lenb);//获取长度 //翻转 for (int i = 0 ; i < lena ; i++) { numa[i] = a[lena - i - 1] - '0'; } for (int i = 0 ; i < lenb ; i++) { numb[i] = b[lenb - i - 1] - '0'; } //竖式计算! for (int i = 0 ; i < lenans ; i++) { ans[i] += numa[i] + numb[i]; } for (int i = 0 ; i < lenans ; i++) { ans[i + 1] += ans[i] / 10; ans[i] %= 10; } //输出 if (ans[lenans] > 0) top = lenans; else top = lenans - 1; for (int i = top ; i >= 0 ; i--) { cout << ans[i]; } return 0; }
-
-3
#include<bits/stdc++.h> using namespace std; #define set(x) Set(x) #define REP(i,j,k) for (int i=(j),_end_=(k);i<=_end_;++i) #define DREP(i,j,k) for (int i=(j),_start_=(k);i>=_start_;--i) #define mp make_pair #define x first #define y second #define pb push_back template<typename T> inline bool chkmin(T &a,const T &b){ return a > b ? a = b, 1 : 0; } template<typename T> inline bool chkmax(T &a,const T &b){ return a < b ? a = b, 1 : 0; } typedef long long LL; typedef pair<int,int> node; const int dmax = 1010, oo = 0x3f3f3f3f; int n, m; int a[dmax][dmax] , ans; int d[dmax], e[dmax]; priority_queue <node> q; inline bool operator >(node a,node b){ return a.y>b.y; } bool p[dmax]; void Set(int x){ p[x] = 1; } void unset(int x){ p[x] = 0; } bool check(int x){ return x != 1 && x != n && !p[x] && e[x] > 0; } void preflow(){ e[1] = oo; d[1] = n - 1; q.push(mp(1, n - 1)); set(1); while (!q.empty()) { bool flag = 1; int k = q.top().x; q.pop(), unset(k); DREP(i, n, 1) if ((d[k] == d[i] + 1 || k == 1) && a[k][i] > 0){ flag = 0; int t = min(a[k][i], e[k]); e[k] -= t; a[k][i] -= t; e[i] += t; a[i][k] += t; if (check(i)) { q.push(mp(i, d[i])); set(i); } if (e[k] == 0) break; } if (flag) { d[k] = oo; REP(i, 1, n) if (a[k][i] > 0) chkmin(d[k], d[i] + 1); } if (check(k)) { q.push(mp(k, d[k])); set(k); } } ans = e[n]; } int main() { n = 2, m = 2; int x, y; scanf("%d%d", &x, &y); a[1][2] += x + y; preflow(); printf("%d\n", ans); return 0; } //也是非常简单
信息
- ID
- 1
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- 6
- 标签
- 递交数
- 26219
- 已通过
- 8163
- 上传者