关闭

hdu4790 Just Random (当心啊!!!)

363人阅读 评论(1) 收藏 举报

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;
}


1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:103953次
    • 积分:3493
    • 等级:
    • 排名:第10092名
    • 原创:247篇
    • 转载:23篇
    • 译文:0篇
    • 评论:24条