题目链接:

hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5203

bc(chinese):http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=575&pid=1002

题解:

不断的分类讨论下去

 #include<algorithm>
#include<iostream>
#include<cstdio>
using namespace std; const int maxn=+;
const int INF=0x3f3f3f3f;
typedef long long LL; int n,m; int main(){
while(scanf("%d%d",&n,&m)==&&n){
//找出bad stick的左右界限
int beg=INF,end=-;
for(int i=;i<m;i++){
int x;
scanf("%d",&x);
beg=min(beg,x);
end=max(end,x);
}
int l1=beg-,l2=n-end;
if(l1>l2) swap(l1,l2);
LL ans=; if(l1>){
//截取的bad stick段在中间
for(int i=;i<l2;i++){
int a=l1,b=i,c=l2-i;
if(a+b>c&&a+c>b&&b+c>a) ans++;
}
}else{
//截取的bad stick段在两边
for(LL x=(l2+)/;x<(l2+)/;x++){
//枚举最长边为x的情况
LL tmp=*x+-l2,cnt=;//tmp代表第一条边为x时的所有合法的情况(后两条边有考虑顺序,第一条边不考虑顺序)
if(l2-*x>){
//最长边有可能存在两条的情况
if(l2-*x==x){
//三条边相等(x,x,x)
cnt=(tmp-)*+;
}else{
if(((l2-x)&)==){
//有两条边相等的情况(1、x,x,a(a<x);2、x,a,a(a<x))
cnt=(tmp-)*+*+*;
}else{
//(x,x,a)
cnt=(tmp-)*+*;
}
}
}else{
//最长边不可能存在两条的情况
if(((l2-x)&)==){
//( x,a,a)
cnt=(tmp-)*+*;
}else{
//(x,b,a(b!=a))
cnt=tmp*;
}
}
ans+=cnt;
}
}
printf("%lld\n",ans);
}
return ;
}

HDU 5203 Rikka with wood sticks 分类讨论的更多相关文章

  1. hdu.5203.Rikka with wood sticks(数学推导:一条长度为L的线段经分割后可以构成几种三角形)

    Rikka with wood sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  2. 【HDOJ】5203 Rikka with wood sticks

    /* 1002 */ #include <iostream> #include <string> #include <map> #include <queue ...

  3. Rikka with wood sticks(hdu5203)

    Rikka with wood sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  4. HDU 6627 equation (分类讨论)

    2019 杭电多校 5 1004 题目链接:HDU 6627 比赛链接:2019 Multi-University Training Contest 5 Problem Description You ...

  5. HDU 6665 Calabash and Landlord (分类讨论)

    2019 杭电多校 8 1009 题目链接:HDU 6665 比赛链接:2019 Multi-University Training Contest 8 Problem Description Cal ...

  6. HDU5957 Query on a graph(拓扑找环,BFS序,线段树更新,分类讨论)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5957 题意:D(u,v)是节点u和节点v之间的距离,S(u,v)是一系列满足D(u,x)<=k的点 ...

  7. HDU 6091 - Rikka with Match | 2017 Multi-University Training Contest 5

    思路来自 某FXXL 不过复杂度咋算的.. /* HDU 6091 - Rikka with Match [ 树形DP ] | 2017 Multi-University Training Conte ...

  8. Codeforces 460D Little Victor and Set --分类讨论+构造

    题意:从区间[L,R]中选取不多于k个数,使这些数异或和尽量小,输出最小异或和以及选取的那些数. 解法:分类讨论. 设选取k个数. 1. k=4的时候如果区间长度>=4且L是偶数,那么可以构造四 ...

  9. BZOJ-1067 降雨量 线段树+分类讨论

    这道B题,刚的不行,各种碎点及其容易忽略,受不鸟了直接 1067: [SCOI2007]降雨量 Time Limit: 1 Sec Memory Limit: 162 MB Submit: 2859 ...

随机推荐

  1. 使用tp3.2和mbUploadify.js上传图片的代码,记录一下

    HTML: <div class="form-group"> <label class="col-sm-1 control-label no-paddi ...

  2. PHP程序员的技术成长规划 第一阶段:基础阶段

    第一阶段:基础阶段(基础PHP程序员) 重点:把LNMP搞熟练(核心是安装配置基本操作)目标:能够完成基本的LNMP系统安装,简单配置维护:能够用PHP源码做基本的简单系统的PHP开发:能够在PHP中 ...

  3. Delphi Compiler Bug?

    I found a Bug of Delphi XE3 Compiler,It may exists in XE4,XE5. Here is the code to show the bug proc ...

  4. 微信小游戏websocket支持https/wss

    公司新项目需要支持wss,解决方法如下: https://blog.csdn.net/peter_teng/article/details/82866613 proxy_pass http://web ...

  5. 深入了解Linux(一)

    Linux的各个文件夹 每次当我使用linux的时候我都被一个个文件夹整懵逼,那么多文件夹到底是怎么分类的呢.今天终于有时间好好整理一下 /boot: 引导文件存放目录,内核文件(vmlinuz),引 ...

  6. 在Ubuntu上开启MongoDB的IP Security

    本文翻译之MongoDB官网博客,原地址:https://www.mongodb.com/blog/post/enabling-ip-security-for-mongodb-36-on-ubuntu ...

  7. 20155216 2016-2017-2《Java程序设计》课程总结

    20155216 2016-2017-2<Java程序设计>课程总结 (按顺序)每周作业链接汇总 预备作业1:简要内容:我对师生关系的见解 预备作业2:简要内容:有关C语言学习调查以及学习 ...

  8. 思维水题 poj1852

    题目链接:http://poj.org/problem?id=1852 题意:木板长为n,    蚂蚁数量为k,    后面k个数,依次代表蚂蚁的位置,  当蚂蚁到达边界的时候会立马掉下,当两个蚂蚁相 ...

  9. pyqt5 菜单,工具栏,线程,matplotlib

    import sys from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import QMainWindow, QMenuBar, QToolBar ...

  10. 【转载】D3DXVec3TransformNormal and D3DXVec3TransformCoord

    原文:D3DXVec3TransformNormal and D3DXVec3TransformCoord D3DXVec3TransformCoord 对向量进行变换,没啥好说明的,默认向量为行向量 ...