NOIP 2012 T2 国王游戏 (贪心+高精)
2016-08-30 23:29
393 查看
思路:
呃呃网上那么多题解写得都不错…..
就是高精 巨坑。。。
这里展出的是任氏高精(纯自己yy滴)
呃呃网上那么多题解写得都不错…..
就是高精 巨坑。。。
这里展出的是任氏高精(纯自己yy滴)
//By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int n,temp[5555],len,A[5555],ans[5555],ans_max; char s[11],jya[11]; struct Node{ char a[11]; int alen,b; }node[1005]; bool cmp(Node x,Node y){ int xa=0,ya=0; for(int i=x.alen-1;~i;i--)xa=xa*10+x.a[i]; for(int i=y.alen-1;~i;i--)ya=ya*10+y.a[i]; return xa*x.b<ya*y.b; } int main(){ scanf("%d",&n); scanf("%s%d",s,&node[0].b); len=strlen(s)-1; for(int i=0;i<=len;i++)A[i]=s[len-i]-'0'; for(int i=1;i<=n;i++){ scanf("%s%d",jya,&node[i].b); node[i].alen=strlen(jya); for(int j=0;j<node[i].alen;j++) node[i].a[j]=jya[node[i].alen-j-1]-'0'; } sort(node+1,node+1+n,cmp); for(int i=1;i<=n;i++){ memset(temp,0,sizeof(temp)); int res=0,maxx=0; for(int j=len;~j;j--){ res=res*10+A[j]; temp[j]=res/node[i].b; if(temp[j])maxx=max(maxx,j); res=res%node[i].b; } for(int j=5000;~j;j--) if(ans[j]<temp[j]){ for(int j=maxx;~j;j--) ans[j]=temp[j]; ans_max=maxx; break; } else if(ans[j]>temp[j])break; memset(temp,0,sizeof(temp)); for(int j=0;j<=len;j++) for(int k=0;k<node[i].alen;k++) temp[j+k]+=A[j]*node[i].a[k]; for(int j=0;j<=len+10;j++){ temp[j+1]+=temp[j]/10; temp[j]=temp[j]%10; if(temp[j])len=j; } for(int j=len;~j;j--)A[j]=temp[j]; } for(int j=ans_max;~j;j--)printf("%d",ans[j]); }
相关文章推荐
- NOIP 2012 T2 国王游戏 (贪心+高精)
- 【贪心+高精度】NOIP2012D1T2国王游戏Codevs1198
- noip 2012 国王游戏(贪心+高精)
- 【NOIP 2012 国王游戏】 贪心+高精度
- [题解] NOIP2012 国王游戏(数论+高精)
- 【noip 2012】国王游戏 贪心+高精度
- 【noip2012 T2】 国王的游戏
- noip2012 国王游戏 (高精除,高精乘+大数比较与替换+数论)
- CODE[VS] 1198【NOIP2012】 国王游戏(贪心
- [NOIP2012]洛谷[P1080]国王游戏 贪心+高精
- Luogu 1080 【NOIP2012】国王游戏 (贪心,高精度)
- 洛谷 1080 [NOIP2012] 国王游戏 贪心+高精
- [NOIP2012][贪心][高精度]国王游戏
- NOIP 2012 国王游戏 贪心 高精度 (COGS 1263)
- [NOIP 2012]国王游戏 高精度+贪心
- 国王游戏 2012年NOIP全国联赛提高组(贪心+高精)
- 【jzoj3100】【NOIP2012提高组】【国王游戏】【贪心】【高精度】
- NOIP 2012 提高组 DAY1 T2 国王游戏
- NOIP 2012 Senior 2 - 国王游戏
- noip2012 国王游戏