您的位置:首页 > 其它

hdu4790 Just Random (当心啊!!!)

2015-11-17 20:24 232 查看
http://acm.hdu.edu.cn/showproblem.php?pid=4790

这道题目教育我不要错在自以为理所应当的地方。。。

#include<iostream>
#include<algorithm>
#include<string>
#include<map>//ll dx[4]={0,0,-1,1};ll dy[4]={-1,1,0,0};
#include<set>//
#include<vector>
#include<cmath>
#include<stack>
#include<string.h>
#include<stdlib.h>
#include<cstdio>
#define mod 1e9+7
#define ll __int64
using namespace std;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int main(){
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
int t,cnt=0;
scanf("%d",&t);
while(t--){
ll a,b,c,d,p,m;
scanf("%I64d%I64d%I64d%I64d%I64d%I64d",&a,&b,&c,&d,&p,&m);
ll aa=a%p;
ll bb=b%p;
ll cc=c%p;
ll dd=d%p;
// cout<<aa<<" "<<bb<<" "<<cc<<" "<<dd<<endl;
ll f1=(b-a)/p,f2=(d-c)/p;
ll ss=f1*f2*p;
if(b/p>a/p&&bb<aa)
bb+=p;
if(d/p>c/p&&dd<cc)
dd+=p;
ll g=m-aa,h=m-bb;
// cout<<h+2*p<<" "<<g+2*p<<endl;
ll s1=0;
s1+=max(0ll,min(g,dd)-max(h,cc)+1);
// cout<<max(0ll,min(g,dd)-max(h,cc)+1)<<endl;
s1+=max(0ll,min(g+p,dd)-max(h+p,cc)+1);
// cout<<max(0ll,min(g+p,dd)-max(h+p,cc)+1)<<endl;
s1+=max(0ll,min(g+2*p,dd)-max(h+2*p,cc)+1);
s1+=max(0ll,min(g+3*p,dd)-max(h+3*p,cc)+1); //这个也要加啊!不加白不加啊!!
// cout<<max(0ll,min(g+2*p,dd)-max(h+2*p,cc)+1)<<endl;
ss+=s1+f1*max(0ll,dd-cc+1)+f2*max(0ll,bb-aa+1);
printf("Case #%d: ",++cnt);
// cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<p<<" "<<m<<" ";
if(ss==0)
printf("0/1\n");
else{
cout<<ss/gcd(ss,(b-a+1)*(d-c+1))<<"/"<<(b-a+1)*(d-c+1)/gcd(ss,(b-a+1)*(d-c+1))<<endl;
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: