UVA计数方法练习[3]
| UVA - 11538 |
题意:n*m放置两个互相攻击的后的方案数
分开讨论行 列 两条对角线
一个求和式
可以化简后计算
//
// main.cpp
// uva11538
//
// Created by Candy on 24/10/2016.
// Copyright © 2016 Candy. All rights reserved.
// #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
inline ll read(){
char c=getchar();ll x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
ll n,m;
int main(int argc, const char * argv[]) {
while((n=read())){
m=read();
if(n>m) swap(n,m);
ll ans=m*(m+n-)*n+*n*(n-)*(*m-n-)/;
printf("%lld\n",ans);
} return ;
}
| UVA - 11401 |
题意:1到n选三个不相同的数组成三角形的方案数
考虑以i为最大边的三角形,i-y<z<i
(i-1)*(i-2)/2 再减去剩下y==z的情况,i/2+1....i-1都可以相等
//
// main.cpp
// uva11401
//
// Created by Candy on 24/10/2016.
// Copyright © 2016 Candy. All rights reserved.
// #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int N=1e6+;
typedef long long ll;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
ll f[N],n;
void dp(){
f[]=;
for(ll i=;i<=1e6;i++)
f[i]=f[i-]+((i-)*(i-)/-(i--i/))/;
}
int main(int argc, const char * argv[]) {
dp();
while((n=read())>=){
printf("%lld\n",f[n]);
}
return ;
}
| UVA - 11806 |
题意:n*m放k个石子,第一行最后一行第一列最后一列都要有
没有的话很好求就是个组合数
二进制枚举集合,利用容斥原理的变式奇负偶正
//
// main.cpp
// uva11806
//
// Created by Candy on 24/10/2016.
// Copyright © 2016 Candy. All rights reserved.
// #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int N=,MOD=;
typedef long long ll;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
int T,n,m,k,f[N][N];
void init(){
f[][]=;
for(int i=;i<=;i++){
f[i][]=f[i][i]=;
for(int j=;j<i;j++) f[i][j]=(f[i-][j]+f[i-][j-])%MOD;
}
}
int main(int argc, const char * argv[]) {
init();
T=read();int cas=;
while(T--){cas++;
n=read();m=read();k=read();
int ans=;
for(int S=;S<;S++){
int b=,r=n,c=m;
if(S&) r--,b++;
if(S&) r--,b++;
if(S&) c--,b++;
if(S&) c--,b++;
if(b&) ans=(ans-f[r*c][k]+MOD)%MOD;
else ans=(ans+f[r*c][k])%MOD;
}
printf("Case %d: %d\n",cas,ans);
} return ;
}
UVA计数方法练习[3]的更多相关文章
- 【spring data jpa】jpa中使用count计数方法
spring data jpa中使用count计数方法很简单 直接在dao层写方法即可 int countByUidAndTenementId(String parentUid, String ten ...
- 【概率论】1-2:计数方法(Counting Methods)
title: [概率论]1-2:计数方法(Counting Methods) categories: Mathematic Probability keywords: Counting Methods ...
- 【基本计数方法---加法原理和乘法原理】UVa 11538 - Chess Queen
题目链接 题意:给出m行n列的棋盘,当两皇后在同行同列或同对角线上时可以互相攻击,问共有多少种攻击方式. 分析:首先可以利用加法原理分情况讨论:①两皇后在同一行:②两皇后在同一列:③两皇后在同一对角线 ...
- php导出excel长数字串显示为科学计数方法与最终解决方法
1.设置单元格为文本 $objPHPExcel = new PHPExcel(); $objPHPExcel->setActiveSheetIndex(0); $objPHPExcel-> ...
- bzoj1272 Gate Of Babylon(计数方法+Lucas定理+乘法逆元)
Description Input Output Sample Input 2 1 10 13 3 Sample Output 12 Source 看到t很小,想到用容斥原理,推一下发现n种数中选m个 ...
- 计数方法,博弈论(扫描线,树形SG):HDU 5299 Circles Game
There are n circles on a infinitely large table.With every two circle, either one contains another o ...
- 计数方法(扫描线):JLOI 2016 圆的异或并
Description 在平面直角坐标系中给定N个圆.已知这些圆两两没有交点,即两圆的关系只存在相离和包含.求这些圆的异或面 积并.异或面积并为:当一片区域在奇数个圆内则计算其面积,当一片区域在偶数个 ...
- [hdu4609]计数方法,FFT
题目:给一个数组a,从里面任选三个数,求以这三个数为三条边能构成三角形的概率. 思路:由于每个数只能用一次,所以考虑枚举三边中的最大边.先将a数组排序,然后枚举它的每个数x作为最大边,那么问题就是要求 ...
- Redis实现唯一计数的3种方法分享
转载于:http://www.itxuexiwang.com/a/shujukujishu/redis/2016/0216/121.html?1455855118 唯一计数是网站系统中十分常见的一个功 ...
随机推荐
- webserver[实时查询当天的天气情况]
1.webserver是什么? 日常生活中经常会使用到webserver,注册时,会收到验证码,购买东西时,会收到短信,假如,A公司网站和B公司合作,那么A公司注册对的用户可以直接推送给B网站,那怎么 ...
- jquery 文本/html/值
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- JVM垃圾回收(GC)原理
一.基本垃圾回收算法 1.引用计数(Reference Counting) 比较古老的回收算法.原理是此对象有一个引用则增加一个引用计数,删除一个引用则较少一个引用计数.垃圾回收时,只回收引用计数为0 ...
- 03-树1 树的同构 (C语言链表实现)
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h& ...
- 【Apache大系】Apache服务器面面观
Apache 2.2 中文官方文档 1. 先看看百度百科对Apache的解释: apache(Web服务器)_百度百科 2. apache服务器本质上说是一个TCP socket服务,socket模型 ...
- position: fixed用在iframe里面失效了
iframe真是各种坑啊,,,可是找不到别的代替 $(parent.window).scroll(function(){ $('固定元素').css({ top : $(parent.window). ...
- 如何使用CSS绘制一个响应式的矩形
背景: 最近因为需要用到绘制类似九宫格的需求,所以研究了一下响应式矩形的实现方案. 有如下几种方案: 使用js来设置元素的高度 使用vw单位 div {width: 50vw; height: 50 ...
- hyper-v上的虚拟机安装linux LC后CDROM无法使用
This issue occurs because the Hyper-V Linux Integration Services unloads the ata_piix driver in orde ...
- 配置 Oracle 11g侦听器来使用SQL操作ST_Geometry(DLL路径问题)
注:http://resources.arcgis.com/zh-cn/help/main/10.2/index.html#/na/00qn0000001p000000/ (ArcGIS 帮助库) 1 ...
- Linux入侵检测常用命令
find / -mtime 0 #0代表目前时间,表示从现在开始到24小时以前,有改动过内容的文件全都会被列出来.如果是3天前24小时内,则使用find / -mtime 3 find /etc -n ...
