首页 > 分享 > 北京师范大学第十四届ACM决赛 I Cactus Exploration 菊花图,仙人掌树

北京师范大学第十四届ACM决赛 I Cactus Exploration 菊花图,仙人掌树

https://www.nowcoder.com/acm/contest/12/I

菊花图:

一个点,这个点与其他所有的点都连通。

来一个灵魂画师吧- - 


菊花图如果每一对与红色点相连的边都相互连,也就是形成一个环的话。

那么最多2*n-2条边,不能再多了。

那么能形成多少个环呢,m-n+1个环。

1.首先的条件,我的边起码得n-1条并且比2*n-2条边少。

2.当m=n的时候形成n边形,此时答案最大n*n

3.然后就得到最后的f(x)=x*(m-(m-n+1-1)*x)

x代表的意思是最小的环的长度,最后的答案一定是一个大环,然后其他全是小环,要不然可以把边加在这个大环里使

答案更大。所以f(x)的最大值为最后的答案,但首先还是要满足一些条件

1.最小的环长度至少是2

2.x<=m/(m-n+1)这个显然。

如果x=2则另x++

/// .-~~~~~~~~~-._ _.-~~~~~~~~~-.

/// __.' ~. .~ `.__

/// .'// ./ `.

/// .'// | `.

/// .'// .-~"""""""~~~~-._ | _,-~~~~"""""""~-. `.

/// .'//.-" `-. | .-' "-.`.

/// .'//______.============-.. | / ..-============.______`.

/// .'______________________________|/______________________________`.

#pragma GCC optimize(2)

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

#include <vector>

#include <iostream>

#include <string>

#include <map>

#include <stack>

#include <cstring>

#include <queue>

#include <list>

#include <stdio.h>

#include <set>

#include <algorithm>

#include <cstdlib>

#include <cmath>

#include <iomanip>

#include <cctype>

#include <sstream>

#include <functional>

#include <stdlib.h>

#include <time.h>

#include <bitset>

using namespace std;

#define pi acos(-1)

#define s_1(x) scanf("%d",&x)

#define s_2(x,y) scanf("%d%d",&x,&y)

#define s_3(x,y,z) scanf("%d%d%d",&x,&y,&z)

#define s_4(x,y,z,X) scanf("%d%d%d%d",&x,&y,&z,&X)

#define S_1(x) scan_d(x)

#define S_2(x,y) scan_d(x),scan_d(y)

#define S_3(x,y,z) scan_d(x),scan_d(y),scan_d(z)

#define PI acos(-1)

#define endl 'n'

#define srand() srand(time(0));

#define me(x,y) memset(x,y,sizeof(x));

#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)

#define close() ios::sync_with_stdio(0); cin.tie(0);

#define FOR(x,n,i) for(int i=x;i<=n;i++)

#define FOr(x,n,i) for(int i=x;i<n;i++)

#define fOR(n,x,i) for(int i=n;i>=x;i--)

#define fOr(n,x,i) for(int i=n;i>x;i--)

#define W while

#define sgn(x) ((x) < 0 ? -1 : (x) > 0)

#define bug printf("***********n");

#define db double

#define ll long long

#define mp make_pair

#define pb push_back

typedef long long LL;

typedef pair <int, int> ii;

const int INF=~0U>>1;

const LL LINF=0x3f3f3f3f3f3f3f3fLL;

const int dx[]={-1,0,1,0,1,-1,-1,1};

const int dy[]={0,1,0,-1,-1,1,-1,1};

const int maxn=1e5+10;

const int maxx=1e3+10;

const double EPS=1e-8;

const double eps=1e-8;

const int mod=1e9+7;

template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}

template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}

template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}

template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}

template <class T>

inline bool scan_d(T &ret){char c;int sgn;if (c = getchar(), c == EOF){return 0;}

while (c != '-' && (c < '0' || c > '9')){c = getchar();}sgn = (c == '-') ? -1 : 1;ret = (c == '-') ? 0 : (c - '0');

while (c = getchar(), c >= '0' && c <= '9'){ret = ret * 10 + (c - '0');}ret *= sgn;return 1;}

inline bool scan_lf(double &num){char in;double Dec=0.1;bool IsN=false,IsD=false;in=getchar();if(in==EOF) return false;

while(in!='-'&&in!='.'&&(in<'0'||in>'9'))in=getchar();if(in=='-'){IsN=true;num=0;}else if(in=='.'){IsD=true;num=0;}

else num=in-'0';if(!IsD){while(in=getchar(),in>='0'&&in<='9'){num*=10;num+=in-'0';}}

if(in!='.'){if(IsN) num=-num;return true;}else{while(in=getchar(),in>='0'&&in<='9'){num+=Dec*(in-'0');Dec*=0.1;}}

if(IsN) num=-num;return true;}

void Out(LL a){if(a < 0) { putchar('-'); a = -a; }if(a >= 10) Out(a / 10);putchar(a % 10 + '0');}

void print(LL a){ Out(a),puts("");}

//freopen( "in.txt" , "r" , stdin );

//freopen( "data.txt" , "w" , stdout );

//cerr << "run time is " << clock() << endl;

//void readString(string &s)

//{

//static char str[maxn];

//scanf("%s", str);

//s = str;

//}

LL n,m;

LL calc(LL x)

{

return x*x*(n-m)+m*x;

}

void solve()

{

S_2(n,m);

if((m<n-1)||(m>2ll*n-2)) print(-1);

else if(m==n-1) print(0);

else if(m==n) print(n*n);

else

{

LL ans=0;

LL p=m/(2ll*(m-n));

if(p>1&&p<=m/(m-n)) ans=max(ans,calc(p));

p++;

if(p<=m/(m-n)) ans=max(ans,calc(p));

print(ans);

}

}

int main()

{

//freopen( "1.in" , "r" , stdin );

//freopen( "1.out" , "w" , stdout );

int t=1;

//init();

s_1(t);

for(int cas=1;cas<=t;cas++)

{

//printf("Case #%d: ",cas);

solve();

}

}

相关知识

一年一度!1500盆菊花里选菊王 第十四届北京菊花擂台赛决赛在丰台举办
第十四届北京菊花擂台赛举办
深圳市第十四届少儿艺术花会原创作品决赛举行 小达人艺术细胞强到离谱
北京参加第十四届中国菊花展览会
树的整理
岳麓山菊花亮相第十四届中国菊花展览会
湖南大学第十四届ACM程序设计大赛 G a+b+c+d=?
第十四届校园插花艺术大赛圆满结束
北京菊花擂台赛决赛举办 “燕山秋色”当选“菊王”
新突破:我院斩获第十四届“挑战杯”中国大学生创业计划竞赛全国决赛银奖

网址: 北京师范大学第十四届ACM决赛 I Cactus Exploration 菊花图,仙人掌树 https://m.huajiangbk.com/newsview781505.html

所属分类:花卉
上一篇: 在元稹的《菊花》一诗中,“不是花
下一篇: 麻城:厚植人才发展沃土 绽放万亩