[hdu5203]计数水题

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

  1 #pragma comment(linker, "/STACK:10240000,10240000")
  2
  3 #include <iostream>
  4 #include <cstdio>
  5 #include <algorithm>
  6 #include <cstdlib>
  7 #include <cstring>
  8 #include <map>
  9 #include <queue>
 10 #include <deque>
 11 #include <cmath>
 12 #include <vector>
 13 #include <ctime>
 14 #include <cctype>
 15 #include <set>
 16 #include <bitset>
 17 #include <functional>
 18 #include <numeric>
 19 #include <stdexcept>
 20 #include <utility>
 21
 22 using namespace std;
 23
 24 #define mem0(a) memset(a, 0, sizeof(a))
 25 #define lson l, m, rt << 1
 26 #define rson m + 1, r, rt << 1 | 1
 27 #define define_m int m = (l + r) >> 1
 28 #define rep0(a, b) for (int a = 0; a < (b); a++)
 29 #define rep1(a, b) for (int a = 1; a <= (b); a++)
 30 #define all(a) (a).begin(), (a).end()
 31 #define lowbit(x) ((x) & (-(x)))
 32 #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) {}
 33 #define constructInt3(name, a, b, c) name(int a = 0, int b = 0, int c = 0): a(a), b(b), c(c) {}
 34 #define constructInt2(name, a, b) name(int a = 0, int b = 0): a(a), b(b) {}
 35 #define pchr(a) putchar(a)
 36 #define pstr(a) printf("%s", a)
 37 #define sint(a) ReadInt(a)
 38 #define sint2(a, b) ReadInt(a);ReadInt(b)
 39 #define sint3(a, b, c) ReadInt(a);ReadInt(b);ReadInt(c)
 40 #define pint(a) WriteInt(a)
 41
 42 typedef double db;
 43 typedef long long LL;
 44 typedef pair<int, int> pii;
 45 typedef multiset<int> msi;
 46 typedef set<int> si;
 47 typedef vector<int> vi;
 48 typedef map<int, int> mii;
 49
 50 const int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
 51 const int dy[8] = {1, 0, -1, 0, -1, 1, 1, -1};
 52 const int maxn = 1e3 + 7;
 53 const int maxm = 1e5 + 7;
 54 const int maxv = 1e7 + 7;
 55 const int max_val = 1e6 + 7;
 56 const int MD = 1e9 +7;
 57 const int INF = 1e9 + 7;
 58 const double PI = acos(-1.0);
 59 const double eps = 1e-10;
 60
 61 template<class T>T gcd(T a, T b){return b==0?a:gcd(b,a%b);}
 62 template<class T>void ReadInt(T &x){char c=getchar();while(!isdigit(c))c=getchar();x=0;while(isdigit(c)){x=x*10+c-‘0‘;c=getchar();}}
 63 template<class T>void WriteInt(T i) {int p=0;static int b[20];if(i == 0) b[p++] = 0;else while(i){b[p++]=i%10;i/=10;}for(int j=p-1;j>=0;j--)pchr(‘0‘+b[j]);}
 64
 65
 66 LL work(int a, int b) {
 67     if (b <= a) return 0;
 68     return max(0, (a + b - 1) / 2 - (b - a) / 2);
 69 }
 70 LL work(int maxv) {
 71     LL ans = 0;
 72     rep1(i, maxv - 1) {
 73         ans += work(i, maxv - i);
 74     }
 75     return ans;
 76 }
 77 int a[1010];
 78 int main() {
 79     //freopen("in.txt", "r", stdin);
 80     int n, m;
 81     while (cin >> n >> m) {
 82         rep0(i, m) {
 83             sint(a[i]);
 84         }
 85         sort(a, a + m);
 86         int minv = a[0] - 1, maxv = n - a[m - 1];
 87         if (minv > maxv) swap(minv, maxv);
 88         if (minv == 0) pint(work(maxv));
 89         else {
 90             if (minv == 1) {
 91                 if (maxv & 1) pint(0);
 92                 else pint(1);
 93             }
 94             else {
 95                 if (minv == maxv) pint(0);
 96                 else pint(work(minv, maxv));
 97             }
 98         }
 99         pchr(‘\n‘);
100     }
101     return 0;
102 }

时间: 2025-01-11 14:30:11

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

poj 1164 The Castle dp区域计数水题

水题,直接贴代码. //poj 1164 //sep9 #include <iostream> using namespace std; int a[64][64]; int dp[64][64]; int n,m; const int west=1,north=2,east=4,south=8; void dfs(int x,int y) { dp[x][y]=1; if((a[x][y]&north)==0&&dp[x-1][y]==-1){ dfs(x-1,y);

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

问题描述 给定n个整数表示一个商店连续n天的销售量.如果某天之前销售量在增长,而后一天销售量减少,则称这一天为折点,反过来如果之前销售量减少而后一天销售量增长,也称这一天为折点.其他的天都不是折点.如下图中,第3天和第6天是折点. 给定n个整数a1, a2, …, an表示销售量,请计算出这些天总共有多少个折点. 为了减少歧义,我们给定的数据保证:在这n天中相邻两天的销售量总是不同的,即ai-1≠ai.注意,如果两天不相邻,销售量可能相同. 输入格式 输入的第一行包含一个整数n. 第二行包含n个

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

题目:https://www.acwing.com/problem/content/232/ #include<bits/stdc++.h> #define ll long long #define mod 1000000007 using namespace std; const int maxn = 1000005; ll dp[maxn],inv[maxn],fac[maxn],inv_fac[maxn]; void init() { inv[0]=inv[1]=inv_fac[0]=f

5.1个人赛解题报告(区间dp,按位与或,图论等水题)

这次5.1打了一场个人赛,已经连赛了三周了,有点疲惫感觉,可能自己太水了,每次都有点小紧张. 这次只解出来三道题,然而有一道按位与按位或的水题不知道思路实在是做题太少,还有就是第一题区间DP,也消耗了不少的时间,但是没有成功的写出来,还是不够熟练啊. 下面写报告 A. System Administrator time limit per test 2 seconds memory limit per test 256 megabytes input standard input output

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

POJ2909_Goldbach&#39;s Conjecture【素数判断】【水题】

Goldbach's Conjecture Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10116 Accepted: 5973 Description For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 and p2 such that n = p1 + p2 This c

两道水题

昨天同桌为我推荐了p1904这道水题,然后他就写不出来了--本来不想写,但是看他写得很麻烦,为了给他展示我的代码能力就写了一下. 即使类型为"其他",但还是掩盖不了模拟的事实.那么直接sort Ai,再在前k个牛中找到Bi最高的就行.复杂度为N*logN+k #include<iostream> #include<iomanip> #include<cstdio> #include<algorithm> using namespace s

11.06水题Test

11.06水题比赛 题目 描述 做法 \(BSOJ5150\) 求\(n\)个数两两之差的中位数 二分中位数,双指针判定\(\le x\)差值对数 \(BSOJ5151\) 求树的最大匹配和其个数 来一遍\(dp\),转移中途计数 \(BSOJ5152\) 求丢一张麻将后最大听牌数 爆搜 \(T1\) 二分中位数,从小到大求出每个点与最小的使得他们差值小于等于\(x\)的位置累加区间,判定两倍是否多于\(\frac{n(n-1)}{2}\) 注意偶数还要二分一次以\(\frac{n(n-1)}{

2015南阳CCPC L - Huatuo&#39;s Medicine 水题

L - Huatuo's Medicine Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Huatuo was a famous doctor. He use identical bottles to carry the medicine. There are different types of medicine. Huatuo put medicines into the bottles and chain these b