ACM-ICPC Nanjing Onsite 2018 G. Pyramid(找规律,推式子)

2018 南京 icpc G. Pyramid

题目

下面分别是 n = 1, 2, 3 时的图案,给出 n 问你图案中有多少等边三角形,(三角形的三个点在顶点上
在这里插入图片描述
ACM-ICPC Nanjing Onsite 2018 G. Pyramid(找规律,推式子)_第1张图片
ACM-ICPC Nanjing Onsite 2018 G. Pyramid(找规律,推式子)_第2张图片

分析

画了一下午三角形,,,

以为是推公式,就手算前 6 项,结果答案越算越多,,,最后退出来前六项,盲猜公式。

ans[i] = n * (n+1) * (n+2) * (n+3) / 24

看别人题解是打表找的,下面是打表程序。(在坐标系中暴力找三点)


#include
#include
#include
#include
#include
#include
//#include
#include
#include
#include
#include
#include
#include
    
#define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x)) 
#define mp make_pair

using namespace std;

typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL;

const db eps = 1e-6;
const int mod = 1e9+7;
const int maxn = 2e6+100;
const int maxm = 2e6+100;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0);

vector<pair<double,double> >v;
struct point{
    double x, y;
    point(){}
    point(double a, double b){x = a; y = b;}
};
double h = 0.5 *sqrt(3);
double len(pair<double,double>a, pair<double,double>b){
    return (a.fst-b.fst)*(a.fst-b.fst)+(a.sc-b.sc)*(a.sc-b.sc);
}
bool eq(double a, double b){
    if(fabs(a-b)<1e-6)return true;
    return false;
}
int main(){
    v.pb(mp(0,0));
    for(int i = 1; i <= 2000; i++){
        if(i&1){
            for(int j = 0; j < i/2+1; j++){
                v.pb(mp(j*1.0+0.5,-i*h));
                v.pb(mp(-j*1.0-0.5,-i*h));
            }
        }
        else{
            v.pb(mp(0,-i*h));
            for(int j = 1; j <= i/2; j++){
                v.pb(mp(j*1.0,-i*h));
                v.pb(mp(-j*1.0,-i*h));
            }
        }
        int cnt = 0;
        for(int j = 0; j < (int)v.size(); j++){
            for(int k = j+1; k < (int)v.size(); k++){
                for(int g = k+1; g < (int)v.size(); g++){
                    if(eq(len(v[j],v[k]),len(v[k],v[g]))&&eq(len(v[j],v[k]),len(v[j],v[g])))cnt++;
                }
            }
        }
        printf("%d\n",cnt);
    }

    return 0;
}
/*
5 0
1 2 3 5
2 5
1 2
10 2
3 10
1 3 4 6 10
3 4 6 8 9
1 9 10
1 3 6 7 10

 */

代码

#include 
using namespace std;
#define ll long long
const int M = 5e5 + 10;
const int N = 3e5 + 10;
const ll mod = 1e9 + 7;

int t;
ll ans, n;

ll pp(ll x, ll y){
	ll res = 1;
	while(y){
		if(y&1)
			res = res * x % mod; 
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}


int main(){
	scanf("%d", &t);
	while(t--){
		scanf("%lld", &n);
		ans = n * (n + 1) % mod * (n + 2) % mod * (n + 3) % mod * pp(24, mod - 2);
		printf("%lld\n", ans % mod);
	}
	return 0;
}

你可能感兴趣的:(解题报告)