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;
}
这道题目教育我不要错在自以为理所应当的地方。。。
#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;
}
相关文章推荐
- 每日学习总结--2D/3D转换
- 杭电1222 Wolf and Rabbit
- 脚本录制-VuGen录制原理
- 从hibernate上理解mybatis
- OpenWrt ar71xx 添加原生 AR8035 支持的方法 (AR934X)
- 机器学习2——python读写excel表格
- 一道题(6)
- 替换空格
- Linux常用命令
- Android中DisplayMetrics 获取手机屏幕分辨率
- LeetCode75——Sort Colors
- 情话
- hadoop 学习笔记(1)
- hihocoder 1257 Snake Carpet 2015 ACM_ICPC 北京区域赛 I 题
- c++OOP程序设计读书笔记之二:程序设计类别
- 史上最全的常用iOS的第三方框架
- CharacterEncodingFilter
- 《第一行代码--Android》读书笔记之日志工具Log与Activity
- linux第一次实验报告
- [国嵌攻略][060][LCD工作原理解析]