HDU5203 Rikka with wood sticks

Problem Description

As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:

Yuta have a wood stick of length n
which consists of n
linked sticks of length 1.
So it has n?1
connection points. Yuta finds that some sticks of length
1
of the wood stick are not strong. So he wants to choose three different connection points to cut it into four wood sticks and only one of them contains wood sticks which are not strong. And Yuta wants to minimize the length of this piece which contains bad
wood sticks. Besides, Rikka wants to use the other three wood sticks to make a triangle. Now she wants to count the number of the ways to cut the wood sticks which can make both Yuta and herself happy.

It is too difficult for Rikka. Can you help her?

Input

This problem has multi test cases (no more than
20).
For each test case, The first line contains two numbers
n,m(1≤n≤1000000,1≤m≤1000).
The next line contains m numbers (some of them may be same) – the position of each wood sticks which is not strong.

Output

For each test cases print only one number – the ways to cut the wood sticks.

Sample Input

6 1
3
5 1
3

Sample Output

2
0

Source

BestCoder Round #37 ($)

Recommend

hujie   |   We have carefully selected several similar problems for you:  5205 5204 5201 5200 5199

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>

#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define eps 1e-8
typedef long long ll;

#define fre(i,a,b)  for(i = a; i <b; i++)
#define free(i,b,a) for(i = b; i >= a;i--)
#define mem(t, v)   memset ((t) , v, sizeof(t))
#define ssf(n)      scanf("%s", n)
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf          printf
#define bug         pf("Hi\n")

using namespace std;

#define INF 0x3f3f3f3f
#define N 400

int n,m;
int le,ri;
int a,b;

void fdd()
{
   a=a+b;
   int i,j;
   ll ans=0;
   for(i=1;i*2<a;i++)
   {
   	 int t=a-i-i;
   	 t/=2;
   	 t++;
   	 int to=a-i-t;
   	 if(to<t) continue;
   	 if(t==0) continue;
   	 ans+=to-t+1;

   }
  pf("%I64d\n",ans);
}

int judge(int x,int y,int z)
{

    if(x+y<=z||x+z<=y) return 0;
    return 1;
}

void solve()
{
    int i,j;
    if(a==0||b==0)
	{
		fdd();
		return ;
	}
    ll ans=0;
    if(a>b) swap(a,b);

    for(i=1;i<b;i++)
	{
		if(judge(a,i,b-i))
			ans++;

	}
    printf("%I64d\n",ans);
}

int main()
{
   int i,j;
   while(~scanf("%d%d",&n,&m))
   {
   	le=INF;
    ri=-1;
    int x;
    while(m--)
	{
		sf(x);
		le=min(le,x);
		ri=max(ri,x);
	}
	 a=le-1;
	 b=n-ri;

	 if(a==b)
	 {
	 	pf("0\n");
	 	continue;
	 }

	 solve();
   }
   return 0;

}

/*

8 1
1

*/
时间: 2024-10-05 03:23:57

HDU5203 Rikka with wood sticks的相关文章

hdu 5203 Rikka with wood sticks(Bestcoder Round #37)

Rikka with wood sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 446    Accepted Submission(s): 130 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situ

hdu 5203 Rikka with wood sticks

题意: 勇太有一根长度为n的木棍,这个木棍是由n个长度为1的小木棍拼接而成,当然由于时间放置的久了,一些小木棍已经不牢固了,所以勇太想让六花把这个木棍分成正整数长度的4段,其中有3段要没有不牢固的小木棍,勇太希望这3段木棍的长度和可以最大.同时六花希望在满足勇太要求的情况下让这三根木棍能拼成一个三角形,请问萌萌哒六花有多少种可行的分割方案呢? 限制: 1 <= n <= 1e6; 1 <= m <= 1e3 思路: 实际上问题会化为: 1. 给出长度为l1,l2的木棒,把其中一根截

【HDOJ】5203 Rikka with wood sticks

1 /* 1002 */ 2 #include <iostream> 3 #include <string> 4 #include <map> 5 #include <queue> 6 #include <set> 7 #include <stack> 8 #include <vector> 9 #include <algorithm> 10 #include <cstdio> 11 #includ

【bestcoder #37】ABC题解

Rikka with string Accepts: 395 Submissions: 2281 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 众所周知,萌萌哒六花不擅长数学,所以勇太给了她一些数学问题做练习,其中有一道是这样的: 有一天勇太得到了一个长度为n的字符串,但是六花一不小心把这个字符串搞丢了.于是他们想要复原这一个字符串.勇太记得这个字符串只包含小写字母而且这

HDU 5135 Little Zu Chongzhi&#39;s Triangles (14广州 状压dp)

Little Zu Chongzhi's Triangles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 474    Accepted Submission(s): 252 Problem Description Zu Chongzhi (429–500) was a prominent Chinese mathematici

[ACM] HDU 5135 Little Zu Chongzhi&#39;s Triangles (一堆木棍组成三角形最大面积)

Little Zu Chongzhi's Triangles Problem Description Zu Chongzhi (429–500) was a prominent Chinese mathematician and astronomer during the Liu Song and Southern Qi Dynasties. Zu calculated the value ofπ to the precision of six decimal places and for a

HDOJ 5135 Little Zu Chongzhi&#39;s Triangles 状压DP

状压DP Little Zu Chongzhi's Triangles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 88    Accepted Submission(s): 49 Problem Description Zu Chongzhi (429–500) was a prominent Chinese mathemat

HDU 5135 Little Zu Chongzhi&#39;s Triangles(贪心)

Little Zu Chongzhi's Triangles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 304    Accepted Submission(s): 180 Problem Description Zu Chongzhi (429–500) was a prominent Chinese mathematici

HDU5135 dfs搜索 枚举种数

Little Zu Chongzhi's Triangles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)Total Submission(s): 2195    Accepted Submission(s): 1262 Problem Description Zu Chongzhi (429–500) was a prominent Chinese mathematic