2018icpc南京现场赛-G Pyramid(打标找规律+逆元)
题意:

求n行三角形中等边三角形个数,图二的三角形也算。
n<=1e9
思路:
打表找下规律,打表方法:把所有点扔坐标系里n^3爆搜即可
打出来为 1,5,15,35,70,126,210..
没感觉,作差 4, 10, 20, 35, 56, 84
还是没感觉,作差 6, 10, 15, 21, 28
发现此时的差递增1?也就是再作差4, 5, 6, 7是等差数列
也就是再作差1, 1, 1为常数
相当于函数$A_n$求四次导为常数!(如果他是个连续函数的话)
于是我们设$\displaystyle A_n = a*n^4+b*n^3+c*n^2+d*n+e$ (别忘记常数)
解出a, b, c, d, e,
然后逆元+O(1)代公式就完事了
打表代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
//#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional> #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-;
const int mod = 1e9+;
const int maxn = 2e6+;
const int maxm = 2e6+;
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();
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-)return true;
return false;
}
int main(){
v.pb(mp(,));
for(int i = ; i <= ; i++){
if(i&){
for(int j = ; j < i/+; 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(,-i*h));
for(int j = ; j <= i/; j++){
v.pb(mp(j*1.0,-i*h));
v.pb(mp(-j*1.0,-i*h));
}
}
int cnt = ;
for(int j = ; j < (int)v.size(); j++){
for(int k = j+; k < (int)v.size(); k++){
for(int g = k+; 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 ;
}
/*
3 5 0
4 1 2 3 5
2 2 5
2 1 2 5 10 2
2 3 10
5 1 3 4 6 10
5 3 4 6 8 9
3 1 9 10
5 1 3 6 7 10 */
2018icpc南京现场赛-G Pyramid(打标找规律+逆元)的更多相关文章
- 2018ICPC南京站Problem G. Pyramid
题意: 找有多少个等边三角形 解析: 首先打标找规律,然后对式子求差分 0,1,5,15,35,70,126,210... 1,4,10,20,35,56... 3,6,10,15,21... 3,4 ...
- 2018icpc南京现场赛-I Magic Potion(最大流)
题意: n个英雄,m个怪兽,第i个英雄可以打第i个集合里的怪兽,一个怪兽可以在多个集合里 有k瓶药水,每个英雄最多喝一次,可以多打一只怪兽,求最多打多少只 n,m,k<=500 思路: 最大流, ...
- 2018ICPC南京网络赛
2018ICPC南京网络赛 A. An Olympian Math Problem 题目描述:求\(\sum_{i=1}^{n} i\times i! \%n\) solution \[(n-1) \ ...
- Gym101981D - 2018ACM-ICPC南京现场赛D题 Country Meow
2018ACM-ICPC南京现场赛D题-Country Meow Problem D. Country Meow Input file: standard input Output file: sta ...
- 2018ICPC青岛现场赛 重现训练
先贴代码,以及简要题解. 和一个队友下午双排打了一下,队友光速签到,我签的J被嫌弃写得慢以及演员...然后我秒出了E了思路然而难以置信这么简单的思路当时才过了十几个,于是发现D.F不是太好做.最后交了 ...
- bzoj1002 轮状病毒 暴力打标找规律/基尔霍夫矩阵+高斯消元
基本思路: 1.先观察规律,写写画画未果 2.写程序暴力打表找规律,找出规律 1-15的答案:1 5 16 45 121 320 841 2205 5776 151 ...
- 2013ACM-ICPC亚洲区南京站现场赛G题
题目大意:一个n维的系统中随机选一个向量(X1,X2,X3,...,Xn),其中0<=Xi<=R,且X1^2+X2^2+X3^2+……+Xn^2 <= R^2. 现在给定n,R.求X ...
- 2018南京区域赛G题 Pyramid——找规律&&递推
先手动推出前10项,再上BM板子求出递推式 $A_n = 5A_{n-1} - 10A_{n-2} + 10A_{n-3} - 5A_{n-4} + A_{n-5}$,根据特征根理论可求出特征方程 $ ...
- hdu-----2491Priest John's Busiest Day(2008 北京现场赛G)
Priest John's Busiest Day Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...
随机推荐
- Flutter 不能热加载,热重载按钮灰色,无法点击,flutter doctor 显示NO_PROXY is not set
一.现象: Flutter 不能热加载 热重载按钮灰色,无法点击. 二.分析原因: 终端 flutter doctor 显示 NO_PROXY is not set 没有设置无代理的端口 终端:flu ...
- 道格拉斯-普克算法(JavaScript实现)
需求: 有时候当移动速度很慢,GPS定位的轨迹点就非常的多,这时候为了缩减数据量,需要将不突出的点去掉. 思路: (1) 在曲线首尾两点间虚连一条直线,求出其余各点到该直线的距离. (2)选其最大者与 ...
- Spring Boot2 系列教程 (九) | SpringBoot 整合 Mybatis
前言 如题,今天介绍 SpringBoot 与 Mybatis 的整合以及 Mybatis 的使用,本文通过注解的形式实现. 什么是 Mybatis MyBatis 是支持定制化 SQL.存储过程以及 ...
- macOS 10.11.* 安装scrapy
1.安装brew,然后修改brew源为某高校 2.更新python brew install python 3.安装pip 4.安装scrapy,这里肯定会有一个坑,之前在网上看到10.11开启了什么 ...
- crawler碎碎念5 豆瓣爬取操作之登录练习
import requests import html5lib import re from bs4 import BeautifulSoup s = requests.Session() #这里要提 ...
- 前端.解决form-contral总是换行问题
form-control 总是会换行,后面加单位的时候很难看,如下图. <div class="col-sm-3"> <input id="invest ...
- Scrapy持久化(items+pipelines)
一.items保存爬取的文件 items.py import scrapy class QuoteItem(scrapy.Item): # define the fields for your ite ...
- Java入门 - 高级教程 - 06.邮件收发
原文地址:http://www.work100.net/training/java-email.html 更多教程:光束云 - 免费课程 邮件收发 序号 文内章节 视频 1 概述 2 发送一封简单的邮 ...
- 【红外DDE算法】数字细节增强算法的缘由与效果(我对FLIR文档详解)
[红外DDE算法]数字细节增强算法的缘由与效果(我对FLIR文档详解) 1. 为什么红外系统中图像大多是14bit(甚至更高)?一个红外系统的性能经常以其探测的范围来区别,以及其对最小等效温差指标.首 ...
- [洛谷P2962] [USACO09NOV] 灯Lights
Description Bessie and the cows were playing games in the barn, but the power was reset and the ligh ...