ACM-ICPC 2017 Asia Urumqi D. Fence Building

Farmer John owns a farm. He first builds a circle fence. Then, he will choose n points and build some straight fences connecting them. Next, he will feed a cow in each region so that cows cannot play with each other without breaking the fences. In order to feed more cows, he also wants to have as many regions as possible. However, he is busy building fences now, so he needs your help to determine what is the maximum number of cows he can feed if he chooses these n points properly.

Input

The first line contains an integer 1 \le T \le 1000001≤T≤100000, the number of test cases. For each test case, there is one line that contains an integer n. It is guaranteed that 1 \le T \le 10^51≤T≤105 and 1 \le n \le 10^{18}1≤n≤1018.

Output

For each test case, you should output a line ”Case #ii: ans” where ii is the test caseS number, starting from 11and ans is the remainder of the maximum number of cows farmer John can feed when divided by 10^9 + 7109+7.

样例输入复制

3
1
3
5

样例输出复制

Case #1: 1
Case #2: 4
Case #3: 16

题目来源

ACM-ICPC 2017 Asia Urumqi

 

题意:在一个圆的圆弧上找n个点,两两之间连线,问你能形成多少个封闭的区域。

题解:太弱了,写出一个长长的公式但是不知道如何化简。。。

观看了两篇题解:https://blog.csdn.net/Lakersilk/article/details/79508863

                             https://blog.csdn.net/hao_zong_yin/article/details/81273280

现在总结一下。QAQ

这种平面或立体中的点,边,面有关系的。具体出门左转百度“欧拉定理 几何”。简单说就是:点 - 边 + 面 = 2

然后这道题让求面,我们只需要求点和边。

我是先把外面的圆先扔掉不看,只看里面的多边形。最后加上n-1即可。

在一个n边形中我们会发现,任取四个不同的点1,2,3,4。我们把(1,3)和(2,4)连边,一定会相交于一点,再算上多边形本身的n个点,一共 n + C(4,n)个点。

边数比较难想,首先我们把n个点,两两连边,这一共有C(2,n)条边,然后我们再对于任选的四个不同的点,我们会发现把(1,3)和(2,4)连边,一定会相交于一点,并且多出两条边(原来的边被切开了)。可以手画一下。然后边数有C(2,n)+2*(4,n)。

所以化简后答案为C(2,n)+C(4,n)+1

因为有模数且是多组数据,所以对于上面这个,我们预处理出2和24的逆元即可得答案。

#include<bits/stdc++.h>
#define LL long long
#define MOD 1000000007
using namespace std;
LL read()
{
	LL s=0,fh=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')fh=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+(ch-'0');ch=getchar();}
	return s*fh;
}
LL ksm(LL bb,LL pp,LL kk)
{
	LL s=1LL;
	while(pp>0LL)
	{
		if(pp%2LL!=0LL)s=(s*bb)%kk;
		pp/=2LL;
		bb=(bb*bb)%kk;
	}
	return s;
}
int main()
{
	LL T,ny2,ny24,n,a1,a2,case1=0LL;
	T=read();
	ny2=ksm(2LL,MOD-2LL,MOD);ny24=ksm(24LL,MOD-2LL,MOD);
	while(T--)
	{
		n=read();
		a1=((((n%MOD)*((n-1LL)%MOD))%MOD)*ny2)%MOD;
		a2=(((n%MOD)*((n-1LL)%MOD)%MOD)*(((n-2LL)%MOD)*((n-3LL)%MOD)%MOD))%MOD;
		a2=(a2*ny24)%MOD;
		printf("Case #%lld: %lld\n",++case1,((a1+a2+1LL)%MOD+MOD)%MOD);
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值