5 条题解
-
0杨跞涵 (rzr123456) LV 5 @ 2023-12-29 17:19:53
~~* Waiting 评测:评测请求正在等待被评测机抓取
- Fetched 评测:评测请求已被评测机抓取,正在准备开始评测
- Compiling 评测:正在编译中
- Compile Error 不通过:编译失败~~
-
02023-5-13 12:02:22@
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> using namespace std; const int MAXN = 1e5 + 10;
int n,lens = 1,lenm = 1,lena = 1; int sum[MAXN] = {0,1}, Max[10010] = {0, 1}, ans[MAXN]; struct node{ long long l, r, all; void read(){ cin >> l >> r; all = l * r; } }coin[MAXN]; bool operator< (node a,node b){ return a.all < b.all; } void mul(long long x){ int tmp = 0; for(int i = 1;i <= lens; i++){ sum[i] *= x; } for(int i = 1;i <= lens; i++){ tmp += sum[i]; sum[i] = tmp % 10; tmp /= 10; } while(tmp != 0){ lens++; sum[lens] = tmp % 10; tmp /= 10; } } void work(long long x){ memset(ans, 0, sizeof(ans)); lena = lens; int tmp = 0; for(int i = lena; i >= 1; i--){ tmp *= 10; tmp += sum[i]; if(tmp >= x){ ans[i] = tmp / x; tmp %= x; } } while(ans[lena] == 0){ if(lena == 1){ break; } lena--; } } void chose(){ if(lena > lenm) { for(int i = 1;i <= lena; i++){ Max[i] = ans[i]; } lenm = lena; } else if(lena == lenm){ for(int i = lena;i >= 1; i--){ if(Max[i] < ans[i]){ for(int j = 1;j <= lena; j++){ Max[j] = ans[j]; } lenm = lena; break; } } } } int main(){ cin >> n; cin >> coin[0].l >> coin[0].r; for(int i = 1;i <= n; i++){ coin[i].read(); } sort(coin + 1, coin + n + 1); for(int i = 1;i <= n; i++){ mul(coin[i - 1].l); work(coin[i].r); chose(); } for(int i = lenm; i >= 1; i--){ cout << Max[i]; } return 0; }
-
02022-2-11 17:40:42@
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> using namespace std; const int MAXN = 1e5 + 10; int n,lens = 1,lenm = 1,lena = 1; int sum[MAXN] = {0,1}, Max[10010] = {0, 1}, ans[MAXN]; struct node{ long long l, r, all; void read(){ cin >> l >> r; all = l * r; } }coin[MAXN]; bool operator< (node a,node b){ return a.all < b.all; } void mul(long long x){ int tmp = 0; for(int i = 1;i <= lens; i++){ sum[i] *= x; } for(int i = 1;i <= lens; i++){ tmp += sum[i]; sum[i] = tmp % 10; tmp /= 10; } while(tmp != 0){ lens++; sum[lens] = tmp % 10; tmp /= 10; } } void work(long long x){ memset(ans, 0, sizeof(ans)); lena = lens; int tmp = 0; for(int i = lena; i >= 1; i--){ tmp *= 10; tmp += sum[i]; if(tmp >= x){ ans[i] = tmp / x; tmp %= x; } } while(ans[lena] == 0){ if(lena == 1){ break; } lena--; } } void chose(){ if(lena > lenm) { for(int i = 1;i <= lena; i++){ Max[i] = ans[i]; } lenm = lena; } else if(lena == lenm){ for(int i = lena;i >= 1; i--){ if(Max[i] < ans[i]){ for(int j = 1;j <= lena; j++){ Max[j] = ans[j]; } lenm = lena; break; } } } } int main(){ cin >> n; cin >> coin[0].l >> coin[0].r; for(int i = 1;i <= n; i++){ coin[i].read(); } sort(coin + 1, coin + n + 1); for(int i = 1;i <= n; i++){ mul(coin[i - 1].l); work(coin[i].r); chose(); } for(int i = lenm; i >= 1; i--){ cout << Max[i]; } return 0; }
-
02021-8-7 18:41:43@
C++ :
#include <iostream> #include <algorithm> #include <vector> using namespace std; typedef pair<int, int>PII; const int N = 1010; int n; PII ps[N]; vector<int> mul(vector<int> a, int b) //高精度乘法 { vector<int> c; int t = 0; for(int i = 0; i < a.size(); i++) { t += a[i] * b; c.push_back(t % 10); //取出余数 t /= 10; //进位 } while(t) c.push_back(t % 10), t /= 10; return c; } vector<int> div(vector<int> a, int b) { vector<int> c; bool is_first = false; // 避免输出前面位的0 for(int i = a.size() - 1, t = 0; i >= 0; i--) //从高位往低位 { t = t * 10 + a[i]; //竖式后位的值 int x = t / b; if(x || is_first) { is_first = true; c.push_back(x); } t %= b; } return vector<int>(c.rbegin(), c.rend()); //逆序遍历 } vector<int> max_vec(vector<int>a, vector<int> b) // 返回vector { if(a.size() > b.size()) return a; if(a.size() < b.size()) return b; if(vector<int>(a.rbegin(), a.rend()) > vector<int>(b.rbegin(), b.rend()))//构造新的vector,是a的逆序 return a; return b; } void output(vector<int> a) { for(int i = a.size() - 1; i >= 0; i--) cout << a[i]; //高精度存,小位在前,高位在后,因为增加一位只能在后面增加 cout << endl; } int main() { cin >> n; for(int i = 0; i <= n; i++) // 0位国王,1...n+1为大臣 { int a, b; cin >> a >> b; ps[i] = {a * b, a}; } sort(ps + 1, ps + n + 1); vector<int>product(1, 1); //乘积长度为1,初始为1 vector<int>res(1,0); // 结果长度为1,初始为0 for(int i = 0; i <= n; i++) { if(i) res = max_vec(res, div(product, ps[i].first / ps[i].second)); product = mul(product, ps[i].second); } output(res); return 0; }
-
-12022-7-20 12:01:58@
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> using namespace std; const int MAXN = 1e5 + 10; int n,lens = 1,lenm = 1,lena = 1; int sum[MAXN] = {0,1}, Max[10010] = {0, 1}, ans[MAXN]; struct node{ long long l, r, all; void read(){ cin >> l >> r; all = l * r; } }coin[MAXN]; bool operator< (node a,node b){ return a.all < b.all; } void mul(long long x){ int tmp = 0; for(int i = 1;i <= lens; i++){ sum[i] *= x; } for(int i = 1;i <= lens; i++){ tmp += sum[i]; sum[i] = tmp % 10; tmp /= 10; } while(tmp != 0){ lens++; sum[lens] = tmp % 10; tmp /= 10; } } void work(long long x){ memset(ans, 0, sizeof(ans)); lena = lens; int tmp = 0; for(int i = lena; i >= 1; i--){ tmp *= 10; tmp += sum[i]; if(tmp >= x){ ans[i] = tmp / x; tmp %= x; } } while(ans[lena] == 0){ if(lena == 1){ break; } lena--; } } void chose(){ if(lena > lenm) { for(int i = 1;i <= lena; i++){ Max[i] = ans[i]; } lenm = lena; } else if(lena == lenm){ for(int i = lena;i >= 1; i--){ if(Max[i] < ans[i]){ for(int j = 1;j <= lena; j++){ Max[j] = ans[j]; } lenm = lena; break; } } } } int main(){ cin >> n; cin >> coin[0].l >> coin[0].r; for(int i = 1;i <= n; i++){ coin[i].read(); } sort(coin + 1, coin + n + 1); for(int i = 1;i <= n; i++){ mul(coin[i - 1].l); work(coin[i].r); chose(); } for(int i = lenm; i >= 1; i--){ cout << Max[i]; } return 0; }
- 1
信息
- ID
- 25
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 1
- 标签
- 递交数
- 134
- 已通过
- 101
- 上传者