#include<algorithm>
#include<cassert>
using namespace std;
#define FOR(i, a, b) for(int i=(a), _b=(b); i<_b; i++)
const int DEBUG=0;
const int HOME=0;
const int MAXK=40;
const int BASE=100000000;
typedef long long LL;
struct bigInt{
int dg[5];
int len;
bigInt(LL v=0){
memset(dg, 0, sizeof dg);
len=5;
FOR(i, 0, len){ dg[i]=v%BASE; v/=BASE; }
while(len>1 && dg[len-1]==0) len--;
}
bool operator<=(const bigInt b)const{
if(len<b.len) return true;
if(len>b.len) return false;
for(int i=len-1; i>=0; i--){
if(dg[i]<b.dg[i]) return true;
if(dg[i]>b.dg[i]) return false;
}
return true;
}
bool operator==(const bigInt b)const{
if(len!=b.len) return false;
for(int i=len-1; i>=0; i--) if(dg[i]!=b.dg[i]) return false;
return true;
}
static void outdg(int n){
char s[10];
sprintf(s,"%d",n);
FOR(l, strlen(s), 8) putchar('0');
printf("%s",s);
}
void output(){
printf("%d",dg[len-1]);
for(int i=len-2; i>=0; --i) outdg(dg[i]);
}
void outputn(){
printf("%d",dg[len-1]);
for(int i=len-2; i>=0; --i) outdg(dg[i]);
putchar('\n');
}
};
bigInt operator+(const bigInt a, const bigInt b){
bigInt ret;
int len=max(a.len, b.len), c=0, v;
FOR(i, 0, len){
v=a.dg[i]+b.dg[i]+c;
ret.dg[i]=v%BASE;
c=v/BASE;
assert(ret.dg[i]>=0 && ret.dg[i]<BASE);
}
if(c) ret.dg[len++]=c;
ret.len=len;
assert(len>0 && ret.dg[len-1]);
return ret;
}
bigInt operator-(const bigInt a, const bigInt b){
bigInt ret;
int len=a.len, c=0, v;
FOR(i, 0, len){
v=a.dg[i]-b.dg[i]-c;
c=v<0?1:0;
ret.dg[i]=c?v+BASE:v;
assert(ret.dg[i]>=0 && ret.dg[i]<BASE);
}
while(len>1 && ret.dg[len-1]==0) len--;
ret.len=len;
assert(len>0);
return ret;
}
int k;
LL p, q, u, v;
bigInt pow[81];
bigInt solve(bigInt u, bigInt v, int sz, bigInt h, bigInt t){
bigInt half, t2, t3, t4, r=u, c=v;
half=pow[sz-1]; t2=t+t; t3=t2+t; t4=t3+t;
if(half<=r) r=r-half; if(half<=c) c=c-half;
int type= u==r ? (v==c?1:2) : (v==c?3:4);
if(!sz) return h;
if(DEBUG){
printf("\nToa do: "); u.output(); printf(","); v.outputn();
printf("Loai : %d\n", type);
printf("Thu tu: "); h.output(); printf("/"); t.outputn();
}
if(type==1) return solve(r, half-c-bigInt(1), sz-1, t+bigInt(1)-h, t4);
if(type==2) return solve(r, c, sz-1, t3+h, t4);
if(type==3) return solve(half-r-bigInt(1), half-c-bigInt(1), sz-1, t+h, t4);
return solve(half-r-bigInt(1), c, sz-1, t3+bigInt(1)-h, t4);
}
int main(){
if(HOME){
freopen("gifts.inp", "r", stdin);
freopen("gifts.out", "w", stdout);
}
pow[0]=bigInt(1);
FOR(i, 1, 81) pow[i]=pow[i-1]+pow[i-1];
if(HOME) scanf("%d %I64d %I64d %I64d %I64d", &k, &p, &q, &u, &v);
else scanf("%d %lld %lld %lld %lld", &k, &p, &q, &u, &v);
solve(bigInt(p), bigInt(q), k, bigInt(1), bigInt(1)).output();
putchar(' ');
solve(bigInt(u), bigInt(v), k, bigInt(1), bigInt(1)).outputn();
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
CPP.zip_SPOJ-HOTELS.cpp_circular game spoj_cpp_segment tree_usac
共112个文件
cpp:79个
pas:31个
exe:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 185 浏览量
2022-09-21
08:09:07
上传
评论
收藏 98KB ZIP 举报
温馨提示
My solution for some spoj problems
资源推荐
资源详情
资源评论
收起资源包目录
CPP.zip_SPOJ-HOTELS.cpp_circular game spoj_cpp_segment tree_usac (112个子文件)
NKGIFTS.cpp 3KB
LUBENICA.cpp 3KB
MATCH2.cpp 2KB
CLOCK.cpp 2KB
QBGAME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 770B
post.cpp 529B
NSP.cpp 417B
COND.exe 73KB
floyd.exe 58KB
BALLGAME.PAS 6KB
V8SORT.PAS 5KB
MATCH2.PAS 4KB
BIGNUM.PAS 4KB
SPSUM.PAS 3KB
GSS.PAS 3KB
NTHUGE.PAS 3KB
CRATE.PAS 3KB
CRUELL.PAS 3KB
MATCH1.PAS 3KB
SUMS.PAS 3KB
MAXCUB.PAS 2KB
NUMBERS.PAS 2KB
CPRIME.PAS 2KB
MAXARR2.PAS 1KB
NTTREE.PAS 1KB
CREC01.PAS 1KB
MAXARR1.PAS 1KB
MATMA.PAS 1KB
共 112 条
- 1
- 2
资源评论
钱亚锋
- 粉丝: 86
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功