hdu 5203 Rikka with wood sticks (暴力枚举边)
来源:互联网 发布:粤贵银交易软件下载 编辑:程序博客网 时间:2024/05/17 04:45
题意:
一段长度为n的木块有n个长度为一的木块构成,现在给出m个不坚固的木块,现在要将原木块分成4份,并且其中三份不能包含不坚固的木块,并且这三份要尽量长,这三份要能构成三角形。问分割的方案数。
题解:
这题三份不能包含不坚固木块,那么其中一份肯定要包含所有木块,于是这要扣掉这一个份,问题就转化成两块木块分成三份或者一块木块分成三份能构成三角形的方案数。
对于第一种情况,两个木块分成三份:直接枚举其中一块的段点,判断三块是否能构成三角形。
对于第二种情况,一块木块分成三份:枚举三角形其中一个边的长度,那么我们可以根据公式算出剩下的木块分成两份,并且能和枚举的边构成三角形的方案数。
#include<iostream>#include<math.h>#include<stdio.h>#include<algorithm>#include<string.h>#include<vector>#include<queue>#include<map>#include<set>#define B(x) (1<<(x))using namespace std;typedef long long ll;void cmax(int& a,int b){ if(b>a)a=b; }void cmin(int& a,int b){ if(b<a)a=b; }void cmax(ll& a,ll b){ if(b>a)a=b; }void cmin(ll& a,ll b){ if(b<a)a=b; }void add(int& a,int b,int mod){ a=(a+b)%mod; }void add(ll& a,ll b,ll mod){ a=(a+b)%mod; }const int oo=0x3f3f3f3f;const ll MOD=100000007;ll calc1(int n){ ll ans=0; for(int i=1;i<=n-2;i++)if(i<n-i){ int l=n-i; ans+=(l+i-1)/2-(l-i)/2; } return ans;}bool ok(int a,int b,int c){ if(a+b>c&&a+c>b&&b+c>a) return true; return false;}ll calc2(int a,int b){ ll ans=0; for(int i=1;i<a;i++){ if(ok(i,a-i,b))ans++; } for(int i=1;i<b;i++){ if(ok(i,b-i,a))ans++; } return ans;}int main(){ int n,m,val; ll ans; int a,b; while(scanf("%d %d",&n,&m)!=EOF){ int l=n,r=0; for(int i=1;i<=m;i++){ scanf("%d",&val); cmin(l,val); cmax(r,val); } ans=0; if(l==1){ ans+=calc1(n-r); }else if(r==n){ ans+=calc1(l-1); }else{ ans+=calc2(l-1,n-r); } cout<<ans<<endl; } return 0;}
0 0
- hdu 5203 Rikka with wood sticks (暴力枚举边)
- HDU 5203 Rikka with wood sticks
- HDU - 5203 Rikka with wood sticks 分析
- hdu 5203 Rikka with wood sticks
- hdu 5203 Rikka with wood sticks
- hdu 5203 Rikka with wood sticks
- HDU 5203 Rikka with wood sticks
- hdu 5203 Rikka with wood sticks(Bestcoder Round #37)
- Rikka with wood sticks
- BestCoder #37 Rikka with wood sticks DFS暴力
- HDU5203 Rikka with wood sticks
- hdu 5425 Rikka with Tree II(暴力)
- HDU 5634 Rikka with Phi(暴力、线段树)
- HDU 6085 Rikka with Candies (暴力压位)
- HDU 5423 Rikka with Tree(简单DFS+枚举)
- HDU Rikka with Graph (并查集+枚举)
- hdu 5631 Rikka with Graph(并查集+枚举)
- Rikka with Tree HDU
- [LeetCode] Best Time to Buy and Sell Stock IV 买卖股票的最佳时间之四
- C++_使用C++代码进行MD5加密
- webview与js交互 问题一
- 图解 Panda3D引擎开发入门
- JAVA:数组
- hdu 5203 Rikka with wood sticks (暴力枚举边)
- linux设备驱动第五篇:驱动中的并发与竟态
- Java:比较运算符compareTo()、equals()、==之间的区别与应用总结
- bash命令提示行设置
- 写给GIS程序员
- Backbone写TODO遇到的诡异空格
- 图示RFID系统信号的通信过程
- Win8.1系统拖拽文件得不到路径的解决办法
- 树 Balanced Binary Tree