23 条题解
-
13小____宅 LV 7 @ 2013-03-12 21:45:48
###贪心证明
假设相邻的两个人左右手分别是(a, b), (A, B)。设a * b <= A * B,i之前所有人的左手乘积为S。
则,ans1 = max{S / b, S * a / B}
若交换
则,ans2 = max{S / B, S * A / b}
因为,a * b <= A * B
所以,S * a / B <= S * A / b
又因为,S / B <= S * a / B
所以,ans2 = S * A / b
ans1 = max{S / B[i], S * a / B}
所以,ans1 <= ans2
证毕
###Code
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#define pii pair<int, int>
#define fi first
#define se second
#define piii pair<int, pii >
const int maxn = 1000 + 2, Len = 4000 + 1, base = 10000;
struct bint
{
int len;
int v[Len];
bint(int r = 0) {for (len = 0; r > 0; r /= base) v[len++] = r % base;}
bint &operator = (const bint &a)
{
memcpy(this, &a, sizeof(int) * (a.len + 1));
return *this;
}
bool operator < (const bint &a)
{
if (len != a.len) return len < a.len;
for (int i = len - 1; i >= 0; i--)
if (v[i] != a.v[i]) return v[i] < a.v[i];
return false;
}
};
ostream &operator << (ostream &out, const bint &a)
{
printf("%d", a.len == 0 ? 0 : a.v[a.len - 1]);
for (int i = a.len - 2; i >= 0; i--) printf("%04d", a.v[i]);
return out;
}
bint operator * (const bint &a, const int &b)
{
bint ans = 0;
if (!a.len || !b) return ans;
int carry = 0, i;
for (i = 0; i < a.len || carry; i++)
{
if (i < a.len) carry += a.v[i] * b;
ans.v[i] = carry % base;
carry /= base;
}
ans.len = i;
return ans;
}
bint operator / (const bint &a, const int &b)
{
bint ans = a;
int carry = 0;
for (int i = ans.len - 1; i >= 0; i--)
{
ans.v[i] += carry * base;
carry = ans.v[i] % b;
ans.v[i] /= b;
}
while (!ans.v[ans.len - 1] && ans.len) ans.len--;
return ans;
}
inline void gmax(bint &a, const bint &b) {if (a < b) a = b;}
int n, a, b;
piii d[maxn];
int main()
{
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++)
scanf("%d%d", &d[i].se.fi, &d[i].se.se), d[i].fi = d[i].se.fi * d[i].se.se;
sort(d + 1, d + n + 1);
bint to = a, ans = 0;
for (int i = 1; i <= n; i++)
{
gmax(ans, to / d[i].se.se);
to = to * d[i].se.fi;
}
cout << ans << endl;
return 0;
} -
52017-07-06 16:38:32@
简单高精度
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int MaxN=1001;
struct NodeTp {
int L;
int R;
int W;
} p[MaxN];
int n,KL,KR;
int a[MaxN],b[MaxN],ans[MaxN];
//比较大小
int ncmp() {
int i;
if (b[0]!=ans[0])
return b[0]-ans[0];
else {
for (i=b[0]; i>=1; i--)
if (b[i]!=ans[i])
return b[i]-ans[i];
return 0;
}
}
//输出结果
void out() {
int i;
printf("%d",ans[ans[0]]);
for (i=ans[0]-1; i>=1; i--)
printf("%4.4d",ans[i]);
}
//高精度*低精度
void mult(int x) {
int i,k=0,tmp;
for (i=1; i<=a[0]||k; i++) {
tmp=a[i]*x+k;
k=tmp/10000;
a[i]=tmp%10000;
}
a[0]=i-1;
}
//高精度/低精度
void div(int x) {
int i,k=0,tmp;
for (i=a[0]; i>=1; i--) {
tmp=a[i]+k*10000;
b[i]=tmp/x;
k=tmp%x;
}
for (i=a[0]; i>1&&!b[i]; i--);
b[0]=i;
}
int cmp(NodeTp a,NodeTp b) {
return a.L*a.R<b.L*b.R;
}
void init() {
int i;
scanf("%d%d%d",&n,&KL,&KR);
for (i=1; i<=n; i++) {
scanf("%d%d",&p[i].L,&p[i].R);
p[i].W=p[i].L*p[i].R;
}
sort(p+1,p+n+1,cmp);
}
void work() {
int i;
a[0]=1,a[1]=KL;
ans[0]=1,ans[1]=0;
for (i=1; i<=n; i++) {
div(p[i].R);
if (ncmp()>0)
memcpy(ans,b,sizeof(b));
mult(p[i].L);
}
}
int main() {
init();
work();
out();
return 0;
} -
32017-09-01 21:42:04@
Python裸题
python
#!/bin/python3
n = int(input())
ka = int(input().split()[0])
z = []
for i in range(0, n):
z.append(list(map(int, input().split())))
z.sort(key = lambda d: d[0] * d[1])
for i in z[0 : n - 1]:
ka = ka * i[0]
print(ka // z[n - 1][1])
-
22017-10-05 21:07:54@
#include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <algorithm> #include <vector> #include <deque> #include <set> #include <limits> #include <string> #include <sstream> using namespace std; const int oo_min=0xcfcfcfcf,oo_max=0x3f3f3f3f; const int max_size=4000; struct p_1 { int a,b,c; }p[1000+1]; int n,ans_size; int ans[max_size]; int sum[max_size]; int temp[max_size]; int cmp_p_1_1(p_1 x,p_1 y) { return x.c<y.c; } int get_size(int *a) { for (int i=max_size;i>=1;i--) if (a[i-1]!=0) return i; return 0; } int cmp_a_1(int *a,int *b) { int a_size=get_size(a),b_size=get_size(b); if (a_size<b_size) return 1; else if (a_size>b_size) return 0; else { for (int i=a_size-1;i>=0;i--) if (a[i]<b[i]) return 1; else if (a[i]>b[i]) return 0; return 0; } } void calc_1(int *a,int b,int *c) { memset(c,0,sizeof(c)); int a_size=get_size(a); for (int i=0;i<a_size;i++) c[i]=a[i]*b; for (int i=0;i<a_size;i++) { if (c[i]>=10&&i==a_size-1) a_size++; c[i+1]+=c[i]/10; c[i]%=10; } } void calc_2(int *a,int b,int *c) { memset(c,0,sizeof(c)); int a_size=get_size(a); for (int i=a_size-1,temp=0;i>=0;i--) { temp=(temp*10)+a[i]; c[i]=temp/b; temp%=b; } } int main() { if (~scanf("%d",&n)) { for (int i=0;i<=n;i++) { scanf("%d%d",&p[i].a,&p[i].b); p[i].c=p[i].a*p[i].b; } sort(&p[1],&p[n+1],cmp_p_1_1); memset(ans,0,sizeof(ans)); memset(sum,0,sizeof(sum)); sum[0]=1; for (int i=0;i<=n;i++) { if (i>0) { memset(temp,0,sizeof(temp)); calc_2(sum,p[i].b,temp); if (cmp_a_1(ans,temp)) memcpy(ans,temp,sizeof(ans)); } memset(temp,0,sizeof(temp)); calc_1(sum,p[i].a,temp); memcpy(sum,temp,sizeof(sum)); } ans_size=get_size(ans); for (int i=ans_size-1;i>=0;i--) printf("%d",ans[i]); printf("\n"); } }
-
12013-11-04 08:10:29@
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;struct peo{
int a,b,ab;
}r[1001];int c[1001],q[1001],n,i,j,len,len1,kinga,kingb,ans[1001],lena;
bool cmp(peo x,peo y)
{
return x.ab<y.ab;
}void bj()
{
int i;
if (lena>len1) return;
else
if (lena==len1)
{
for (i=lena; i>=1; i--)
if (q[i]<ans[i]) return;
else if (q[i]>ans[i]) break;
if (i==0) return;
}
for (i=len1; i>=1; i--)
ans[i]=q[i];
lena=len1;
}void chu(int k)
{
for (j=len1; j>=2; j--)
q[j-1]+=q[j]%r[i].b*10000,q[j]/=r[i].b;
q[1]/=r[i].b;
while (q[len1]==0)
len1--;
}void cheng(int k)
{
for (j=1; j<=len; j++)
c[j]*=r[i].a;
for (j=1; j<=len; j++)
if (c[j]>10000)
c[j+1]+=c[j]/10000,c[j]%=10000;
while (c[len+1]>0)
len++,c[len+1]+=c[len]/10000,c[len]%10000;
}int main()
{
scanf("%d",&n);
scanf("%d %d",&kinga,&kingb);
for (i=1; i<=n; i++)
scanf("%d %d",&r[i].a,&r[i].b),r[i].ab=r[i].a*r[i].b;
sort(r+1,r+n+1,cmp);
c[1]=kinga; len=1;
for (i=1; i<=n; i++)
{
memcpy(q,c,sizeof(c)),len1=len;
chu(r[i].b);
bj();
cheng(r[i].a);
}
printf("%d",ans[lena]);
for (j=lena-1; j>=1; j--)
{
if (ans[j]<1000) printf("0");
if (ans[j]<100) printf("0");
if (ans[j]<10) printf("0");
printf("%d",ans[j]);
}
return 0;
} -
02023-05-28 15:32:45@
贪心算法足矣.
注意不考虑大数只有60分哦~import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] king = { sc.nextInt(), sc.nextInt() };
int[][] dc = new int[n][2];
for (int i=0; i<n; i++) {
dc[i][0] = sc.nextInt();
dc[i][1] = sc.nextInt();
}for (int i=0; i<n-1; i++) {
for (int j=i + 1; j<n; j++) {
int a = dc[i][0];
int b = dc[i][1];if( Math.max(dc[j][1], a*b) > Math.max(b, dc[j][0]*dc[j][1]) ) {
dc[i][0] = dc[j][0];
dc[i][1] = dc[j][1];
dc[j][0] = a;
dc[j][1] = b;
}}
}BigInteger money = new BigInteger("0");
BigInteger s = new BigInteger(king[0] + "");for (int i=0; i<n; i++) {
BigInteger dci1 = new BigInteger(dc[i][1] + "");
BigInteger sDiv = s.divide(dci1);if (sDiv.compareTo( money ) == 1) {
money = sDiv;
}BigInteger dci0 = new BigInteger(dc[i][0] + "");
s = s.multiply(dci0);
}System.out.println(money.toString());
}
} -
02018-08-01 09:09:44@
高中时代做的题拿java水一发
import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; class People implements Comparable<People> { BigInteger a, b; public BigInteger getA() { return a; } public void setA(BigInteger a) { this.a = a; } public BigInteger getB() { return b; } public void setB(BigInteger b) { this.b = b; } //定义compareTo方法来使用Collections.sort() @Override public int compareTo(People rhs) { return a.multiply(b).subtract(rhs.a.multiply(rhs.b)).compareTo(BigInteger.valueOf(0)); } } public class Main { private static BigInteger max(BigInteger a, BigInteger b) { if (a.compareTo(b) < 0) return b; else return a; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n; People king = new People(); People buf; ArrayList<People> p = new ArrayList<>(); while (sc.hasNext()) { n = sc.nextInt(); king.setA(sc.nextBigInteger()); king.setB(sc.nextBigInteger()); for (int i = 0; i < n; i++) { buf = new People(); //ArrayList.add()方法传的是引用,所以要保证每次初始化一个新的对象 buf.setA(sc.nextBigInteger()); buf.setB(sc.nextBigInteger()); p.add(buf); } Collections.sort(p); BigInteger ans = BigInteger.valueOf(0); BigInteger sum = king.getA(); for (int i = 0; i < n; i++) { ans = max(ans, sum.divide(p.get(i).getB())); sum = sum.multiply(p.get(i).getA()); } System.out.println(ans); } } }
//60分做法 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int MAXN = 1000 + 5; int n,a[MAXN],b[MAXN]; struct c{ int a,b; bool operator < (const c & rhs) const { return (long long)a*b < (long long)rhs.a*rhs.b; } }c[MAXN]; int main(){ int n; scanf("%d",&n); for(int i=0;i<=n;i++){ scanf("%d%d",&c[i].a,&c[i].b); } sort(c+1,c+1+n); int ans=0,sum=c[0].a; for(int i=1;i<=n;i++){ ans=max(ans,sum/c[i].b); sum*=c[i].a; } printf("%d\n",ans); return 0; }
-
02017-07-06 16:57:41@
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int MaxN=1001;
struct NodeTp {
int L;
int R;
int W;
} p[MaxN];
int n,KL,KR;
int a[MaxN],b[MaxN],ans[MaxN];
//比较大小
int ncmp() {
int i;
if (b[0]!=ans[0])
return b[0]-ans[0];
else {
for (i=b[0]; i>=1; i--)
if (b[i]!=ans[i])
return b[i]-ans[i];
return 0;
}
}
//输出结果
void out() {
int i;
printf("%d",ans[ans[0]]);
for (i=ans[0]-1; i>=1; i--)
printf("%4.4d",ans[i]);
}
//高精度*低精度
void mult(int x) {
int i,k=0,tmp;
for (i=1; i<=a[0]||k; i++) {
tmp=a[i]*x+k;
k=tmp/10000;
a[i]=tmp%10000;
}
a[0]=i-1;
}
//高精度/低精度
void div(int x) {
int i,k=0,tmp;
for (i=a[0]; i>=1; i--) {
tmp=a[i]+k*10000;
b[i]=tmp/x;
k=tmp%x;
}
for (i=a[0]; i>1&&!b[i]; i--);
b[0]=i;
}
int cmp(NodeTp a,NodeTp b) {
return a.L*a.R<b.L*b.R;
}
void init() {
int i;
scanf("%d%d%d",&n,&KL,&KR);
for (i=1; i<=n; i++) {
scanf("%d%d",&p[i].L,&p[i].R);
p[i].W=p[i].L*p[i].R;
}
sort(p+1,p+n+1,cmp);
}
void work() {
int i;
a[0]=1,a[1]=KL;
ans[0]=1,ans[1]=0;
for (i=1; i<=n; i++) {
div(p[i].R);
if (ncmp()>0)
memcpy(ans,b,sizeof(b));
mult(p[i].L);
}
}
int main() {
init();
work();
out();
return 0;
} -
02014-08-24 14:16:51@
#include <cstdio>
#include <iostream>
using namespace std;const int MaxN=1001;
struct NodeTp
{int L;//左手上的数
int R;//右手上的数
int W;//两者乘积
}p[MaxN];int n,KL,KR;
int a[MaxN],b[MaxN],ans[MaxN];int ncmp()//比较两个高精度数的大小
{int i;
if (b[0]!=ans[0])
return b[0]-ans[0];
else
{for (i=b[0];i>=1;i--)
if (b[i]!=ans[i]) return b[i]-ans[i];
return 0;
}
}void out()//输出:数组的每一位存4位数(即万进制)
{int i;
printf("%d",ans[ans[0]]);
for (i=ans[0]-1;i>=1;i--)
printf("%4.4d",ans[i]);
}void mult(int x)//高精度乘单精度数x
{int i,k=0,tmp;
for (i=1;i<=a[0]||k;i++)
{tmp=a[i]*x+k;
k=tmp/10000;
a[i]=tmp%10000;
}
a[0]=i-1;//a[0]存位数
}void div(int x)//高精度除以单精度数x
{int i,k=0,tmp;
for (i=a[0];i>=1;i--)
{tmp=a[i]+k*10000;
b[i]=tmp/x;
k=tmp%x;
}
for (i=a[0];i>1&&!b[i];i--);
b[0]=i;//b[0]存位数
}int cmp(const void* a,const void* b)
{NodeTp x=*(NodeTp )a;
NodeTp y=(NodeTp *)b;
return x.W > y.W ? 1:-1;
}void init()
{int i;
scanf("%d%d%d",&n,&KL,&KR);
for (i=1;i<=n;i++)
{scanf("%d%d",&p[i].L,&p[i].R);
p[i].W=p[i].L*p[i].R;
}
qsort(p+1,n,sizeof(p[1]),cmp);//按左手数*右手数从小到大排序
}void work()
{int i;
a[0]=1,a[1]=KL;
ans[0]=1,ans[1]=0;
for (i=1;i<=n;i++)
{div(p[i].R);//b[]记录第i个大臣获得的金币数
if (ncmp()>0) memcpy(ans,b,sizeof(b));
mult(p[i].L);////a[]记录从国王到第i个大臣左手上的数的乘积
}
}int main()
{freopen("game.in","r",stdin);
freopen("game.out","w",stdout);
init();
work();
out();
return 0;
} -
02014-08-08 14:38:06@
高精度数组记得要定大点,至少4001,为了凑个整数我定了5000……
#include <iostream> #include <cstring> using namespace std; long l[5001],ans[5001],Max[5001]; long len; void cf(long x) { long i,g; g=0; for (i=1;i<=len;i++){ l[i]=l[i]*x+g; g=l[i]/10; l[i]=l[i]%10; } while (g!=0){ l[i]=l[i]+g; g=l[i]/10; l[i]=l[i]%10; i++; } len=i-1; } void c(long x) { long i,g; memset(ans,0,sizeof(ans)); g=0; for (i=len;i>=1;i--){ ans[i]=(g*10+l[i])/x; g=(g*10+l[i])%x; } } void bj() { long i; for (i=len;i>=1;i--) if (Max[i]<ans[i]){ memcpy(Max,ans,sizeof(ans)); break; } else if (Max[i]>ans[i])break; } main() { long a[1001],b[1001],i,j,k,n; cin>>n; for (i=0;i<=n;i++) cin>>a[i]>>b[i]; for (i=1;i<n;i++) for (j=i+1;j<=n;j++) if (a[i]*b[i]>a[j]*b[j]){ k=a[i]; a[i]=a[j]; a[j]=k; k=b[i]; b[i]=b[j]; b[j]=k; } memset(l,0,sizeof(l)); len=0; while (a[0]!=0){ len++; l[len]=a[0]%10; a[0]=a[0]/10; } for (i=1;i<=n;i++){ c(b[i]); bj(); cf(a[i]); } len=5000; while (Max[len]==0) len--; for (i=len;i>=1;i--) cout<<Max[i]; }
-
02014-01-01 12:01:58@
Vijos 题解:http://hi.baidu.com/umule/item/2c997f8ed9600fdae596e017
有疑问请留言 共同进步 -
-22016-09-12 18:36:21@
可算AC了
卡死我了
vijos数据太弱了
没有比较数组都能过#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
int n,t,z,nmp,tmp,k,ans;
int x[10000];
int y[10000];
int cheng[10000];
int lx;int ly;
struct your
{
int r,e;
}q[1011];
bool cmp(your m,your n)
{
if(m.r*m.e==n.r*n.e)
{
return m.e<n.e;
}
else
{
return m.r*m.e<n.r*n.e;
}
}
void init()
{
memset(x,0,sizeof x);
lx=0;tmp=0;nmp=0;ans=0;
return;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n+1;i++)
{
scanf("%d%d",&q[i].r,&q[i].e);
}
sort(q+2,q+n+2,cmp);
t=1;
cheng[1]=1;
for(int w=2;w<=n+1;w++)
{
tmp=0;nmp=0;
for(int j=1;j<=t;j++)
{
tmp=cheng[j]*q[w-1].r+nmp;
cheng[j]=tmp%10;
nmp=tmp/10;
if(j==t&&nmp>0)
{
t++;
}
}
k=0;
for(int i=t;i>=1;i--)
{
ans=ans*10+cheng[i];
if(ans/q[w].e!=0){k=1;}
if(k==1)
{
lx++;
x[lx]=ans/q[w].e;
}
ans=ans%q[w].e;
}
int jk=0;
if(ly<lx)
{
for(int z=lx;z>=0;z--) y[z]=x[z];
ly=lx;
}
else
{
if(ly==lx)
{
for(int v=1;v<=lx;v++)
{
if(y[v]<x[v])
{
jk=1;
break;
}
}
if(jk==1)
{
for(int z=lx;z>=0;z--) y[z]=x[z];
jk=0;
}
}
}
init();
}
for(int i=1;i<=ly;i++)
{
printf("%d",y[i]);
}
} -
-22013-07-17 10:50:20@
type dd=array[0..5000] of longint;
var
a,b,p,d,py,ans,c:dd;
n,i,j,t:longint;function time(a:dd; b:longint):dd;
var i,len:longint;
begin
len:=a[0]; fillchar(c,sizeof(c),0);
for i:=1 to len do
c[i]:=c[i]+a[i]*b;
for i:=1 to len do
begin
c[i+1]:=c[i+1]+c[i] div 10;
c[i]:=c[i] mod 10;
end;
while c[len+1]>0 do
begin
inc(len);
c[len+1]:=c[len] div 10;
c[len]:=c[len] mod 10;
end;
c[0]:=len;
time:=c;
end;function divide(a:dd;b:longint):dd;
var i,len,d:longint;
begin
len:=a[0]; fillchar(c,sizeof(c),0);
d:=0;
for i:=len downto 1 do
begin
d:=d*10+a[i];
c[i]:=d div b;
d:=d mod b;
end;
while (len>=1) and (c[len]=0) do dec(len);
c[0]:=len;
divide:=c;
end;function max(a,b:dd):boolean;
var i:longint;
begin
if a[0]>b[0] then exit(true);
if a[0]<b[0] then exit(false);
for i:=a[0] downto 1 do
if a[i]>b[i] then exit(true)
else if a[i]<b[i] then exit(false);
exit(false);
end;
begin
readln(n); py[0]:=1; py[1]:=1;
readln(a[0],b[0]); py:=time(py,a[0]);
for i:=1 to n do
begin
readln(a[i],b[i]);
p[i]:=a[i]*b[i];
end;
for i:=1 to n-1 do
for j:=i+1 to n do
if p[j]<p[i] then
begin
t:=a[i]; a[i]:=a[j]; a[j]:=t;
t:=b[i]; b[i]:=b[j]; b[j]:=t;
t:=p[i]; p[i]:=p[j]; p[j]:=t;
end;
ans[0]:=0;
for i:=1 to n do
begin
d:=divide(py,b[i]);
if max(d,ans) then ans:=d;
py:=time(py,a[i]);
end;
for i:=ans[0] downto 1 do
write(ans[i]);
end. -
-32016-11-17 21:09:02@
一个用vector实现的高精度
C++
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct Wint:vector<int>
{
Wint(const int &n=0)
{
push_back(n);
check();
}
Wint& check()
{
while(!empty()&&!back())pop_back();
if(empty())return *this;
for(int i=1; i!=size(); ++i)
{
(*this)[i]+=(*this)[i-1]/10;
(*this)[i-1]%=10;
}
while(back()>=10)
{
push_back(back()/10);
(*this)[size()-2]%=10;
}
return *this;
}
};
ostream& operator<<(ostream &os,const Wint &w)
{
for(int i=w.size()-1; i!=-1; --i)os<<w[i];
return w.empty()?os<<0:os;
}
bool operator<(const Wint &a,const Wint &b)
{
if(a.size()!=b.size())return a.size()<b.size();
for(int i=a.size()-1; i!=-1; --i)
if(a[i]!=b[i])return a[i]<b[i];
return 0;
}
Wint& operator*=(Wint &w,const int &n)
{
for(int i=0; i!=w.size(); ++i)w[i]*=n;
return w.check();
}
Wint operator/(Wint w,const int &n)
{
for(int i=w.size()-1,mod=0; i!=-1; --i)
{
w[i]+=mod*10;
mod=w[i]%n;
w[i]/=n;
}
return w.check();
}
struct People
{
int a,b;
};
bool operator<(const People &m,const People &n)
{
if(m.a*m.b!=n.a*n.b)return m.a*m.b<n.a*n.b;
if(m.a!=n.a)return m.a<n.a;
return 0;
}
int main()
{
vector<People> v(1);
int n;
Wint s=1,ans=0;
cin>>n>>v.back().a>>v.back().b;
while(n--)
{
v.push_back(v.front());
cin>>v.back().a>>v.back().b;
}
sort(v.begin()+1,v.end());
for(int i=1; i!=v.size(); ++i)
{
s*=v[i-1].a;
ans=max(ans,s/v[i].b);
}
cout<<ans;
}
-
-32014-08-24 14:20:21@
不好意思,头文件没粘上来
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
using namespace std;
const int MaxN=1001;
struct NodeTp
{int L;
int R;
int W;
}p[MaxN];
int n,KL,KR;
int a[MaxN],b[MaxN],ans[MaxN];
int ncmp()
{int i;
if (b[0]!=ans[0])
return b[0]-ans[0];
else
{for (i=b[0];i>=1;i--)
if (b[i]!=ans[i]) return b[i]-ans[i];
return 0;
}
}
void out()
{int i;
printf("%d",ans[ans[0]]);
for (i=ans[0]-1;i>=1;i--)
printf("%4.4d",ans[i]);
}
void mult(int x)
{int i,k=0,tmp;
for (i=1;i<=a[0]||k;i++)
{tmp=a[i]*x+k;
k=tmp/10000;
a[i]=tmp%10000;
}
a[0]=i-1;
}
void div(int x)
{int i,k=0,tmp;
for (i=a[0];i>=1;i--)
{tmp=a[i]+k*10000;
b[i]=tmp/x;
k=tmp%x;
}
for (i=a[0];i>1&&!b[i];i--);
b[0]=i;
}
int cmp(const void* a,const void* b)
{NodeTp x=*(NodeTp )a;
NodeTp y=(NodeTp *)b;
return x.W > y.W ? 1:-1;
}
void init()
{int i;
scanf("%d%d%d",&n,&KL,&KR);
for (i=1;i<=n;i++)
{scanf("%d%d",&p[i].L,&p[i].R);
p[i].W=p[i].L*p[i].R;
}
qsort(p+1,n,sizeof(p[1]),cmp);
}
void work()
{int i;
a[0]=1,a[1]=KL;
ans[0]=1,ans[1]=0;
for (i=1;i<=n;i++)
{div(p[i].R);
if (ncmp()>0) memcpy(ans,b,sizeof(b));
mult(p[i].L);
}
}
int main()
{
init();
work();
out();
return 0;
} -
-32014-08-08 14:36:09@
高精度数组记得要定大点,至少4001,为了凑个整数我定了5000……
#include <iostream>
#include <cstring>
using namespace std;
long l[5001],ans[5001],Max[5001];
long len;
void cf(long x)
{
long i,g;
g=0;
for (i=1;i<=len;i++){
l[i]=l[i]*x+g;
g=l[i]/10;
l[i]=l[i]%10;
}
while (g!=0){
l[i]=l[i]+g;
g=l[i]/10;
l[i]=l[i]%10;
i++;
}
len=i-1;
}
void c(long x)
{
long i,g;
memset(ans,0,sizeof(ans));
g=0;
for (i=len;i>=1;i--){
ans[i]=(g*10+l[i])/x;
g=(g*10+l[i])%x;
}
}
void bj()
{
long i;
for (i=len;i>=1;i--)
if (Max[i]<ans[i]){
memcpy(Max,ans,sizeof(ans));
break;
} else if (Max[i]>ans[i])break;
}
main()
{
long a[1001],b[1001],i,j,k,n;
cin>>n;
for (i=0;i<=n;i++)
cin>>a[i]>>b[i];
for (i=1;i<n;i++)
for (j=i+1;j<=n;j++)
if (a[i]*b[i]>a[j]*b[j]){
k=a[i];
a[i]=a[j];
a[j]=k;
k=b[i];
b[i]=b[j];
b[j]=k;
}
memset(l,0,sizeof(l));
len=0;
while (a[0]!=0){
len++;
l[len]=a[0]%10;
a[0]=a[0]/10;
}
for (i=1;i<=n;i++){
c(b[i]);
bj();
cf(a[i]);
}
len=5000;
while (Max[len]==0) len--;
for (i=len;i>=1;i--) cout<<Max[i];
} -
-32013-07-15 17:16:19@
快排+高精乘+高精除
var
i,n,l:longint;
a,b,c:array[0..10000] of longint;
g,g2:array[0..100000] of longint;
procedure gj1;//高精乘
var
j:longint;
begin
for j:=1 to l do g[j]:=g[j]*b[i];
for j:=1 to l do
begin
g[j+1]:=g[j+1]+g[j] div 10;
g[j]:=g[j] mod 10;
end;
inc(l);
while g[l]>9 do
begin
g[l+1]:=g[l+1]+g[l] div 10;
g[l]:=g[l] mod 10;
inc(l);
end;
if g[l]=0 then dec(l);
end;
procedure gj2;//高精除
var
j:longint;
begin
for j:=l downto 1 do
begin
g[j-1]:=g[j-1]+(g[j] mod c[n])*10;
g[j]:=g[j] div c[n];
end;
while g[l]=0 do dec(l);
end;
procedure sort(l,r:longint);
var
i,j,x,y:longint;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2];
repeat
while a[i]<x do inc(i);
while x<a[j] do dec(j);
if not (i>j) then
begin
y:=a[i];
a[i]:=a[j];
a[j]:=y;
y:=b[i];
b[i]:=b[j];
b[j]:=y;
y:=c[i];
c[i]:=c[j];
c[j]:=y;
inc(i);
dec(j);
end;
until (i>j);
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
begin
readln(n);
readln(b[0],c[0]);
for i:=1 to n do
begin
read(b[i],c[i]);
a[i]:=b[i]*c[i];
end;
sort(1,n);
l:=1;
g[1]:=b[0];
for i:=1 to n-1 do gj1;
gj2;
for i:=l downto 1 do write(g[i]);
writeln;
end. -
-32012-11-20 17:38:35@
Sofa
-
-42016-11-18 18:24:21@
program game; uses math; const size = 10000; type hugeint = record len: integer; num: array [1..size] of longint; end; arr = array [0..1000] of integer; var n: integer; a, b: arr; i, j: integer; c, d: longint; big, z, cal: hugeint; function get(a: integer): integer; var s: string; ans: integer; begin str(a, s); ans := length(s); exit(ans); end; procedure geth(var a: hugeint); var i: longint; begin for i := 1 to size do if a.num[i] > 0 then a.len := i; end; function transh(a: longint): hugeint; var i: integer; s: string; ans: hugeint; begin str(a, s); fillchar(ans, sizeof(ans), 0); ans.len := length(s); for i := ans.len downto 1 do ans.num[i] := ord(s[ans.len - i + 1]) - 48; exit(ans); end; function over(a, b: hugeint): boolean; var i: longint; begin if (a.len < b.len) then exit(false); if (a.len > b.len) then exit(true); for i := a.len downto 1 do begin if a.num[i] < b.num[i] then exit(false); if a.num[i] > b.num[i] then exit(true); end; exit(true); end; function times(a: hugeint; b: integer): hugeint; var i, j: longint; ans: hugeint; begin fillchar(ans, sizeof(ans), 0); for i := 1 to a.len do ans.num[i] := a.num[i] * b; for i := 1 to (a.len + get(b) - 1) do begin inc(ans.num[i + 1], ans.num[i] div 10); ans.num[i] := ans.num[i] mod 10; end; geth(ans); exit(ans); end; function devide(a: hugeint; b: integer): hugeint; var i, j, d: longint; ans: hugeint; begin fillchar(ans, sizeof(ans), 0); d := 0; for i := a.len downto 1 do begin d := d * 10 + a.num[i]; while d >= b do begin ans.num[i] := d div b; d := d mod b; end; end; geth(ans); exit(ans); end; procedure print(a: hugeint); var i: longint; begin for i := a.len downto 1 do write(a.num[i]); end; procedure qsort(var a, b: arr; left, right: integer); var i, j: integer; k, temp: longint; begin if (left >= right) then exit; i := left; j := right; k := a[i] * b[i]; while (i <> j) do begin while (a[j] * b[j] >= k) and (j>i) do dec(j); while (k >= a[i] * b[i]) and (i<j) do inc(i); if (i < j) then begin temp := a[i]; a[i] := a[j]; a[j] := temp; temp := b[i]; b[i] := b[j]; b[j] := temp; end; end; temp := a[left]; a[left] := a[i]; a[i] := temp; temp := b[left]; b[left] := b[i]; b[i] := temp; qsort(a, b, left, i - 1); qsort(a, b, i + 1, right); end; begin // assign(input,'game.in'); assign(output,'game.out'); // reset(input); rewrite(output); read(n); for i := 0 to n do read(a[i], b[i]); qsort(a, b, 1, n); fillchar(big, sizeof(big), 0); fillchar(z,sizeof(z), 0); z := transh(a[0]); for i := 1 to n do begin cal := devide(z, b[i]); z := times(z, a[i]); if over(cal, big) then big := cal; end; print(big); // close(input); close(output); end.
-
-42015-10-28 21:19:59@
这道题考的是RP啊= =看得出贪心了就不一样了。。不然只能乖乖算..