Skip to content

Instantly share code, notes, and snippets.

@lackofdream
Created April 21, 2015 08:51
Show Gist options
  • Select an option

  • Save lackofdream/c94a85b94bdfbce8405b to your computer and use it in GitHub Desktop.

Select an option

Save lackofdream/c94a85b94bdfbce8405b to your computer and use it in GitHub Desktop.
HDU5203
#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <vector>
#include <fstream>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#define MAX(a,b) (a>b?a:b)
#define sd(x) scanf("%d",&x)
#define sdd(a,b) scanf("%d%d",&a,&b)
#define sddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define slflf(x,y) scanf("%lf%lf",&x,&y)
#define abs(x) (x<0?(-x):x)
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
using namespace std;
int length[3];
long long calcSegment(int len)
{
long long ret = 0;
if (len%2==0)
{
for (int i = 1;i<len/2;i++)
{
ret+=(i-1);
}
}
else
{
for (int i=1;i<len/2+1;i++)
{
ret+=i;
}
}
return ret;
}
int main()
{
int n,m,tmp;
while(~sdd(n,m))
{
int leftCut=100000000,rightCut=0;
for (int i=0; i<m; i++)
{
sd(tmp);
if (tmp>rightCut) rightCut=tmp;
if (tmp-1<leftCut) leftCut=tmp-1;
}
long long cnt =0 ;
if (leftCut != 0 && rightCut != n)
{
for (int i=1; i<n; i++)
{
if (i <= rightCut && i >= leftCut) continue;
if (i < leftCut)
{
length[0]=i;
length[1]=leftCut-i;
length[2]=n-rightCut;
}
else
{
length[0]=leftCut;
length[1]=i-rightCut;
length[2]=n-i;
}
if (length[0]+length[1]>length[2] && \
length[1]+length[2]>length[0] && \
length[0]+length[2]>length[1])
{
cnt++;
}
}
}
else if (leftCut == 0 && rightCut == n)
{
cnt=0;
}
else
{
cnt = calcSegment(n-rightCut+leftCut);
}
cout << cnt << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment