思路:把一个木棍分成3段,使之能够构成三角形的方案总数可以这样计算,枚举一条边,然后可以推公式算出当前方案数。对于已知一条边的情况,也用公式推出。用max和min并维护下,以减少情况数目。

 #pragma comment(linker, "/STACK:10240000,10240000")

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <ctime>
#include <cctype>
#include <set>
#include <bitset>
#include <functional>
#include <numeric>
#include <stdexcept>
#include <utility> using namespace std; #define mem0(a) memset(a, 0, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define define_m int m = (l + r) >> 1
#define rep0(a, b) for (int a = 0; a < (b); a++)
#define rep1(a, b) for (int a = 1; a <= (b); a++)
#define all(a) (a).begin(), (a).end()
#define lowbit(x) ((x) & (-(x)))
#define constructInt4(name, a, b, c, d) name(int a = 0, int b = 0, int c = 0, int d = 0): a(a), b(b), c(c), d(d) {}
#define constructInt3(name, a, b, c) name(int a = 0, int b = 0, int c = 0): a(a), b(b), c(c) {}
#define constructInt2(name, a, b) name(int a = 0, int b = 0): a(a), b(b) {}
#define pchr(a) putchar(a)
#define pstr(a) printf("%s", a)
#define sint(a) ReadInt(a)
#define sint2(a, b) ReadInt(a);ReadInt(b)
#define sint3(a, b, c) ReadInt(a);ReadInt(b);ReadInt(c)
#define pint(a) WriteInt(a) typedef double db;
typedef long long LL;
typedef pair<int, int> pii;
typedef multiset<int> msi;
typedef set<int> si;
typedef vector<int> vi;
typedef map<int, int> mii; const int dx[] = {, , , -, , , -, -};
const int dy[] = {, , -, , -, , , -};
const int maxn = 1e3 + ;
const int maxm = 1e5 + ;
const int maxv = 1e7 + ;
const int max_val = 1e6 + ;
const int MD = 1e9 +;
const int INF = 1e9 + ;
const double PI = acos(-1.0);
const double eps = 1e-; template<class T>T gcd(T a, T b){return b==?a:gcd(b,a%b);}
template<class T>void ReadInt(T &x){char c=getchar();while(!isdigit(c))c=getchar();x=;while(isdigit(c)){x=x*+c-'';c=getchar();}}
template<class T>void WriteInt(T i) {int p=;static int b[];if(i == ) b[p++] = ;else while(i){b[p++]=i%;i/=;}for(int j=p-;j>=;j--)pchr(''+b[j]);} LL work(int a, int b) {
if (b <= a) return ;
return max(, (a + b - ) / - (b - a) / );
}
LL work(int maxv) {
LL ans = ;
rep1(i, maxv - ) {
ans += work(i, maxv - i);
}
return ans;
}
int a[];
int main() {
//freopen("in.txt", "r", stdin);
int n, m;
while (cin >> n >> m) {
rep0(i, m) {
sint(a[i]);
}
sort(a, a + m);
int minv = a[] - , maxv = n - a[m - ];
if (minv > maxv) swap(minv, maxv);
if (minv == ) pint(work(maxv));
else {
if (minv == ) {
if (maxv & ) pint();
else pint();
}
else {
if (minv == maxv) pint();
else pint(work(minv, maxv));
}
}
pchr('\n');
}
return ;
}

[hdu5203]计数水题的更多相关文章

  1. zzulioj--1707--丧心病狂的计数(水题)

    1707: 丧心病狂的计数 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 237  Solved: 105 SubmitStatusWeb Board ...

  2. CCF 201604-1 折点计数 (水题,暴力)

    问题描述 给定n个整数表示一个商店连续n天的销售量.如果某天之前销售量在增长,而后一天销售量减少,则称这一天为折点,反过来如果之前销售量减少而后一天销售量增长,也称这一天为折点.其他的天都不是折点.如 ...

  3. AcWing 230. 排列计数 水题(组合数+错排)打卡

    题目:https://www.acwing.com/problem/content/232/ #include<bits/stdc++.h> #define ll long long #d ...

  4. 水题 ZOJ 3869 Ace of Aces

    题目传送门 水题,找出出现次数最多的数字,若多个输出Nobody //#include <bits/stdc++.h> //using namespace std; #include &l ...

  5. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  6. hdu 2553:N皇后问题(DFS遍历,水题)

    N皇后问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  7. 11.06水题Test

    11.06水题比赛 题目 描述 做法 \(BSOJ5150\) 求\(n\)个数两两之差的中位数 二分中位数,双指针判定\(\le x\)差值对数 \(BSOJ5151\) 求树的最大匹配和其个数 来 ...

  8. 水题大战Vol.3 B. DP搬运工2

    水题大战Vol.3 B. DP搬运工2 题目描述 给你\(n,K\),求有多少个\(1\)到\(n\) 的排列,恰好有\(K\)个数\(i\) 满足\(a_{i-1},a_{i+1}\) 都小于\(a ...

  9. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

随机推荐

  1. Cucumber(2)——目录结构以及基本语法

    目录 回顾 HelloWorld 扩展 回顾 在上一节中,我大致的介绍了一下cucumber的特点,以及基于ruby和JavaScript下关于cucumber环境的配置,如果你还没有进行相关的了解或 ...

  2. Python父类和子类关系/继承

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @File:继承_子类和父类的关系.py @E-mail:364942 ...

  3. linq深入

    一.匿名类:[ C# 3.0/.NET 3.x 新增特性 ] 1.1 不好意思,我匿了 在开发中,我们有时会像下面的代码一样声明一个匿名类:可以看出,在匿名类的语法中并没有为其命名,而是直接的一个ne ...

  4. Calendar日历类

    package com.yhqtv.demo02.ThreadPool; import java.util.Calendar; import java.util.Date; /* * java.uti ...

  5. Java 使用正则表达式和IO实现爬虫以及503解决

    我这边找了个小说网站: 基本套路: 第一步:获取小说每一章的url地址 第二步:获取章节url内容并使用正则表达式提取需要的内容 第三步:多线程封装,实现如下效果 最后测试. 代码: 内容获取封装: ...

  6. mac使用brew安装mysql5.7

    安装mysql5.7 brew install mysql@5.7 设置环境变量(可能安装完自动生成过了,可以cat ~/.zshrc看一下,有了就不用添加了 ) echo 'export PATH= ...

  7. printf 参数检查 __attribute__((format(printf, 1, 2)))

    With GCC, I can specify __attribute__((format(printf, 1, 2))) , telling the compiler that this funct ...

  8. Task Scheduler Error Message: 80041318

    Using the error lookup tool that comes with VC++ (errlook.exe, or "Error Lookup" on the To ...

  9. mysql 之 函数

    聚合函数 avg()函数 - 计算一组值或表达式的平均值. count()函数 - 计算表中的行数. instr()函数 - 返回子字符串在字符串中第一次出现的位置. sum()函数 - 计算一组值或 ...

  10. 【Linux题目】第六关

    [定时任务规则] 1. 如果在某用户的crontab文件中有以下记录,该行中的命令多久执行一次(RHCE考试题)?( ) 30 4 * * 3 mycmd A. 每小时. B. 每周. C. 每年三月 ...