LL AB(LL x,LL y,LL m)//让a*b%m不越界
{
LL res=0;
while(y)
{
if(y&1) res=(res+x)%m;
x=(x*2)%m;
y>>=1;
}
return res%m;
}
void cuopai(){//错排公式
f[1] = 0,f[2] = 1;
for(int i = 3;i <= maxn;i++)
f[i] = (i - 1) * ( f[i-1] + f[i-2] );
}
/********** 计算几何 *********/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
#define eps 1e-8
int top,n;
//点
struct POINT
{
double x, y;
int pnd;
POINT(){ }
POINT(double a, double b){
x = a;
y = b;
}
}p[10005],st[10005];
//线段
struct Seg
{
POINT a, b;
Seg() { }
Seg(POINT x, POINT y){
a = x;
b = y;
}
};
//叉乘
double cross(POINT o, POINT a, POINT b)
{
return (a.x - o.x) * (b.y - o.y) - (b.x - o.x) * (a.y - o.y);
}
//判断点在线段上
bool On_Seg(POINT a, Seg s)
{
double maxx = max(s.a.x, s.b.x), minx = min(s.a.x, s.b.x);
double maxy = max(s.a.y, s.b.y), miny = min(s.a.y, s.b.y);
if(a.x >= minx && a.x <= maxx && a.y >= miny && a.y <= maxy) return true;
return false;
}
//判断线段相交
bool Seg_cross(Seg s1, Seg s2)
{
double cs1 = cross(s1.a, s2.a, s2.b);
double cs2 = cross(s1.b, s2.a, s2.b);
double cs3 = cross(s2.a, s1.a, s1.b);
double cs4 = cross(s2.b, s1.a, s1.b);
// 互相跨立
if(cs1 * cs2 < 0 && cs3 * cs4 < 0) return true;
if(cs1 == 0 && On_Seg(s1.a, s2)) return true;
if(cs2 == 0 && On_Seg(s1.b, s2)) return true;
if(cs3 == 0 && On_Seg(s2.a, s1)) return true;
if(cs4 == 0 && On_Seg(s2.b, s1)) return true;
return false;
}
//求两条线段的交点,但是,必须保证线段相交且不共线
//共线的话需要特判
POINT Inter(Seg s1, Seg s2)
{
double k = fabs(cross(s1.a, s2.a, s2.b)) / fabs(cross(s1.b, s2.a, s2.b));
return POINT((s1.a.x + s1.b.x * k) / (1 + k), (s1.a.y + s1.b.y * k) / (1 + k));
}
//多边形面积,需要有顺序,顺(逆)时针。
double area()
{
double ans = 0;
for(int i = 1; i < top; i ++){
ans += cross(p[0], p[i], p[i + 1]);
}
return ans;
}
//找凸包基点排序
bool cmp0(POINT a, POINT b)
{
if(a.y < b.y) return true;
else if(a.y == b.y && a.x < b.x) return true;
return false;
}
//极角排序
double dis(POINT a , POINT b){
return sqrt( (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) );
}
bool cmp1(POINT a, POINT b)
{
if(cross(p[0], a, b) > eps) return true;
else if(fabs(cross(p[0], a, b)) < eps && dis(p[0], a) - dis(p[0], b) > eps) return true;
return false;
}
//Graham_scan 求凸包.所求为纯净凸包...,当凸包点数为2(周长)要特判 即两点的距离
double Graham_scan()
{
sort(p, p + n, cmp0);
sort(p + 1, p + n, cmp1);
top = 0;
p[n] = p[0];
st[top ++] = p[0]; st[top ++] = p[1];
for(int i = 2; i <= n; i ++){
while(top > 2 && (cross(st[top - 1], st[top - 2], p[i]) > eps || fabs(cross(st[top - 1], st[top - 2], p[i])) < eps)) top --;
st[top ++] = p[i];
}
top --;
}
void init(){//素数打表
cnt = 0;
memset(vis,false,sizeof(vis));
for(int i = 2;i < maxn ;i++){
if(!vis[i]){
prime[cnt ++] = i;
for(int j = i + i; j < maxn;j += i)
vis[j] = true;
}
}
}
int gcd(int a,int b){//最大公约数
return b == 0 ? a : gcd(b,a%b);
}
int lcm(int a,int b){//最小公倍数
return a * b / gcd(a,b);
}
int x,y;
int exgcd(int a,int b){//乘法逆元
if(b == 0) {x = 1,y = 0;}
else{
exgcd(b,a%b);
int tmp = x;
x = y,y = tmp - a / b * y;
}
}
</pre><pre name="code" class="cpp"><pre name="code" class="cpp">Manacher's ALGORITHM: O(n)时间求字符串的最长回文子串
int Manacher(char *str)
{
int len = strlen(str), p[N * 2];
memset(p, 0, sizeof(p));
//rebuild the string..
char newstr[N * 2]; newstr[0] = '$';
for(int i = 0; i < len; i ++){
newstr[i * 2 + 1] = '#';
newstr[i * 2 + 2] = str[i];
}
newstr[len * 2 + 1] = '#'; newstr[len * 2 + 2] = '\0';
//id记录目前最长回文串的中心,mx为其右边界.
int id = 0, mx = 0, ans = -1;
for(int i = 1; newstr[i] != '\0'; i ++){
int j = 2 * id - i;
p[i] = mx > i ? min(p[j], mx - i) : 1;
while(newstr[i + p[i]] == newstr[i - p[i]]) p[i] ++;
if(i + p[i] > mx){
id = i; mx = i +p[i];
}
if(p[i] > ans) ans = p[i];
}
return ans - 1;
}
补充:使用 Manacher 算法后我们得到了一个 len 数组,利用它我们可以在 O(1) 的时间内判断该字符串的任意子串是不是回文串,方法如下:
bool Query(int l, int r) //判断源串中的某一子串 ss[l...r] 是否为回文串
{
return p[l + r + 2] >= r - l + 1;
}
/**************************************************************************
题意:给你三角形外接圆和内切圆的半径分别为R,r,求出一个可行的三角形。
题解:对于无解的情况,我们能很快搞掉。
然后我们能发现等腰三角形就能构造出所有的情况,
于是只要算出等腰三角形的情况就好了。
欧拉定理 (R - r) ^ 2 = d ^ 2 + r ^ 2
其中 d 是内心和外心的距离。
***************************************************************************/
#include <bits/stdc++.h>
using namespace std;
int main() {
double r, R;
while (scanf("%lf%lf", &r, &R) == 2) {
if (2 * r > R) {
puts("NO Solution!");
continue;
}
double d = sqrt(R * R - 2.0 *r * R);
double y = sqrt((d + R) * (d + R) - r * r);
double x = 2.0 * R * sqrt(1 - (r * r / (R + d) / (R + d)));
printf("%.18lf %.18lf %.18lf\n", x, x, 2.0 * (x - y));
}
return 0;
}