Uva 12075 Counting Triangles(容斥)
2015-08-19 16:22
357 查看
/* 思路:1.先选三个点 2.去掉同行情况 3.去掉同列情况 4.枚举矩形大小去掉重复情况 */ #pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<queue> #include<stack> #include<vector> #include<set> #include<map> #define L(x) (x<<1) #define R(x) (x<<1|1) #define MID(x,y) ((x+y)>>1) #define bug printf("hihi\n") #define eps 1e-8 //typedef __int64 ll; typedef long long ll; using namespace std; #define INF 0x3f3f3f3f #define N 1005 int n,m; ll C(ll n,ll m) { if(m>n) return 0; ll ans=1; for(int i=0;i<m;i++) ans=ans*(n-i)/(i+1); return ans; } int main() { int i,j,ca=0; while(scanf("%d%d",&n,&m),n+m) { ll ans=C((n+1)*(m+1),3); ans-=(ll)C(n+1,3)*(m+1)+(ll)C(m+1,3)*(n+1); // cout<<ans<<endl; for(i=1;i<=n;i++) for(j=1;j<=m;j++) { int c=__gcd(i,j); ans-=(ll)(c-1)*(n-i+1)*(m-j+1)*2; // ans-=(ll)(C(c,2)*(n-i+1)*(m-j+1)*2;//之前wa 的地方这样 // printf("%d %d %d %lld\n",i,j,c,(ll)C(c,2)*(n-i+1)*(m-j+1)*2); } printf("Case %d: %lld\n",++ca,ans); } return 0; }
相关文章推荐
- Android 数据存储与IO之File存储
- JavaScript学习笔记之类型之间的判断比较
- CodeForces 441 A. Valera and Antique Items
- linux强制umount设备的方法
- iframe自适应高度(兼容多种浏览器)
- 桌面支持--Fixed objects will move
- Java集合深入学习--HashSet与TreeSet
- 桌面支持--excel字母变数字解决办法
- Python函数式编程指南(三):迭代器
- AC自动机+DP 改变字符串中的‘?’使得在字典中匹配到的次数最多 codechef Lucy and Question Marks
- 归档空间问题处理总结
- codeforces 71C C. Round Table Knights(枚举)
- Sublime Text使用笔记
- hosts.deny hosts.allow防止ssh暴力破解密码
- 编写高质量代码改善C#程序的157个建议——建议78:应避免线程数量过多
- 桌面支持--excel自动换行
- CSS3边框阴影,折角效果演示
- 用java下载网页
- Robotium 中如何重签名
- Swift学习笔记系列——(23)泛型