Codeforces Round 465 div.2 C&D

C. Fifa and Fafa
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Fifa and Fafa are sharing a flat. Fifa loves video games and wants to download a new soccer game. Unfortunately, Fafa heavily uses the internet which consumes the quota. Fifa can access the internet through his Wi-Fi access point. This access point can be accessed within a range of r meters (this range can be chosen by Fifa) from its position. Fifa must put the access point inside the flat which has a circular shape of radius R. Fifa wants to minimize the area that is not covered by the access point inside the flat without letting Fafa or anyone outside the flat to get access to the internet.

The world is represented as an infinite 2D plane. The flat is centered at (x1, y1) and has radius R and Fafa's laptop is located at (x2, y2), not necessarily inside the flat. Find the position and the radius chosen by Fifa for his access point which minimizes the uncovered area.

Input

The single line of the input contains 5 space-separated integers R, x1, y1, x2, y2 (1 ≤ R ≤ 105|x1|, |y1|, |x2|, |y2| ≤ 105).

Output

Print three space-separated numbers xap, yap, r where (xap, yap) is the position which Fifa chose for the access point and r is the radius of its range.

Your answer will be considered correct if the radius does not differ from optimal more than 10 - 6 absolutely or relatively, and also the radius you printed can be changed by no more than 10 - 6 (absolutely or relatively) in such a way that all points outside the flat and Fafa's laptop position are outside circle of the access point range.

Examples
input
Copy
5 3 3 1 1
output
3.7677669529663684 3.7677669529663684 3.914213562373095
input
Copy
10 5 5 5 15
output
5.0 5.0 10.0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define eps 1e-8
#define pi  3.141592653589793
//二维点类
struct Point
{
    long double x,y;
    Point(long double a=0,long double b=0){x=a;y=b;}
};

typedef Point Vector;

//二维直线类,一般方程ax+by+c=0
struct Line
{
    long double a,b,c,angle;
    Point p1,p2;
    Line(Point s,Point e)
    {
        a=s.y-e.y;
        b=e.x-s.x;
        c=s.x*e.y-e.x*s.y;
        angle=atan2(e.y-s.y,e.x-s.x);
        p1=s;p2=e;
    }
    Line(){}
};
//采用eps的精度判断大/小于零
ll epssgn(long double x)
{
    if (fabs(x)<eps) return 0;
    else return x<0?-1:1;
}

void CircleCrossLine(Point a,Point b,Point o,long double r,Point ret[],ll &num)
{
    long double x0=o.x,y0=o.y;
    long double x1=a.x,y1=a.y;
    long double x2=b.x,y2=b.y;
    long double dx=x2-x1,dy=y2-y1;
    long double A=dx*dx+dy*dy;
    long double B=2*dx*(x1-x0)+2*dy*(y1-y0);
    long double C=(x1-x0)*(x1-x0)+(y1-y0)*(y1-y0)-r*r;
    long double delta=B*B-4*A*C;
    num=0;
    if (epssgn(delta)>=0)
    {
        long double t1=(-B-sqrt(fabs(delta)))/(2*A);
        long double t2=(-B+sqrt(fabs(delta)))/(2*A);
            ret[num++]=Point(x1+t1*dx,y1+t1*dy);
            ret[num++]=Point(x1+t2*dx,y1+t2*dy);
    }
}
int main(){
double R, x1, y1, x2, y2; ll n, num = 0;
cin>>R>>x1>>y1>>x2>>y2;
Point cross_p[2];
if ((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1) > R * R) {
	cout<< setprecision(20) << x1 <<" "<< y1 <<" "<< R <<endl;
	return 0;
}
if (x1 == x2 && y1 == y2){
     CircleCrossLine(Point(x1, y1), Point(x2+R/2, y2+R/2), Point(x1, y1), R, cross_p, num);
}
else CircleCrossLine(Point(x1, y1), Point(x2, y2), Point(x1, y1), R, cross_p, num);
/*cout<<num<<endl;
for (ll i=0; i<num; i++){
	cout<<cross_p[i].x<<" "<<cross_p[i].y<<endl;
}*/
long double d1 = (cross_p[0].x - x2) * (cross_p[0].x - x2) + (cross_p[0].y - y2) * (cross_p[0].y - y2);
long double d2 = (cross_p[1].x - x2) * (cross_p[1].x - x2) + (cross_p[1].y - y2) * (cross_p[1].y - y2);
if (d1 > d2){
	cout<< setprecision(20) << (cross_p[0].x + x2)/ 2.0 <<" "<<(cross_p[0].y + y2)/ 2.0<<" "<< sqrt(d1) / 2.0<<endl;
}
else{
	cout<< setprecision(20) << (cross_p[1].x + x2)/ 2.0 <<" "<<(cross_p[1].y + y2)/ 2.0<<" "<< sqrt(d2) / 2.0<<endl;
}
}
WTF 模版里面用两点确定直线, 然而两个点重合时 就变成了nan 然后我居然改成了+R/2 结果R=0 的时候R/2又变成了nan WTF
D. Fafa and Ancient Alphabet
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Ancient Egyptians are known to have used a large set of symbols  to write on the walls of the temples. Fafa and Fifa went to one of the temples and found two non-empty words S1 and S2 of equal lengths on the wall of temple written one below the other. Since this temple is very ancient, some symbols from the words were erased. The symbols in the set  have equal probability for being in the position of any erased symbol.

Fifa challenged Fafa to calculate the probability that S1 is lexicographically greater than S2. Can you help Fafa with this task?

You know that , i. e. there were m distinct characters in Egyptians' alphabet, in this problem these characters are denoted by integers from 1 to m in alphabet order. A word x is lexicographically greater than a word y of the same length, if the words are same up to some position, and then the word x has a larger character, than the word y.

We can prove that the probability equals to some fraction , where P and Q are coprime integers, and . Print as the answer the value , i. e. such a non-negative integer less than 109 + 7, such that , where  means that a and b give the same remainders when divided by m.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the length of each of the two words and the size of the alphabet , respectively.

The second line contains n integers a1, a2, ..., an (0 ≤ aim) — the symbols of S1. If ai = 0, then the symbol at position i was erased.

The third line contains n integers representing S2 with the same format as S1.

Output

Print the value , where P and Q are coprime and  is the answer to the problem.

Examples
input
Copy
1 2
0
1
output
500000004
input
Copy
1 2
1
0
output
0
input
Copy
7 26
0 15 12 9 13 0 14
11 1 0 13 15 12 0
output
230769233
Note

In the first sample, the first word can be converted into (1) or (2). The second option is the only one that will make it lexicographically larger than the second word. So, the answer to the problem will be , that is 500000004, because .

In the second example, there is no replacement for the zero in the second word that will make the first one lexicographically larger. So, the answer to the problem is , that is 0.

解1 扩欧 中间要修改一下 不然要炸掉 见注释
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const ll maxn = 1e5 + 5;
const ll mod = 1e9+7;
long long zongshu = 1, da = 0, deng = 1;
  
ll extended_euclid(ll a,ll b,ll& x,ll& y)  
{  
    ll d = a;  
    if(b){
        d = extended_euclid(b,a % b,y,x);  
        y = (y - (a / b) * x) % mod;  ///唯一需要保护的就是这里
    }  
    else{    
        x = 1;  
        y = 0;  
    }  
    return d;  
}  
  
void solve(ll a,ll b,ll d,ll& x,ll& y)  
{  
    ll gcd = extended_euclid(a,b,x,y);
    x = x * d;  
    ll t = b;  
    x = (x % t + t) % t;  
    y = (d - a * x) / b;  ///溢出也无所谓 反正不要y 而且很大程度上x不溢出的代价就是y溢出
}  
  
int main(){
	ll n, m, x, y, s1_gr_s2 = 0;
	int s1[maxn], s2[maxn];
	cin>>n>>m;
	for (ll i=0; i<n; i++){
		scanf("%d", &s1[i]);
	}
	for (ll i=0; i<n; i++){
		scanf("%d", &s2[i]);
	}

	for (ll i=0; i<n; i++){	

		if (s1[i] == 0){

			if (s2[i] == 0) {
				da = ( ((da * m % mod) * m) % mod + ((m*(m-1)/2 % mod) * deng) % mod) % mod;
				zongshu = (((zongshu * m) % mod) * m) % mod;
				deng = deng * m % mod;
				continue;
			}

			zongshu = zongshu * m % mod;

			da = (da*m % mod  + deng * (m-s2[i]) % mod) % mod;
			continue;
		}
		
		if (s2[i] == 0){
			da = (da * m % mod + deng * (s1[i]-1) % mod) % mod;
			zongshu = zongshu * m % mod;
			continue;
		}

		if (s1[i] > s2[i]) {
			da = (da + deng) % mod;
			break;
		}
		if (s1[i] < s2[i]){
			if (!da) {
				cout<<0<<endl;
				return 0;
			}
			break;	
		}
	}
	ll ans, c;
    solve(zongshu, mod, da, ans, c); 
    cout<<ans<<endl;    
   
    return 0;  

}
解2 最方便用 模拟元https://www.cnblogs.com/ECJTUACM-873284962/p/6847672.html
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const ll maxn = 1e5 + 5;
const ll mod = 1e9+7;
long long zongshu = 1, da = 0, deng = 1;

ll inv(ll x){
	ll base = x, ans = 1;
	for (ll i = mod-2; i; i/=2){
		if (i&1){
			ans = ans * base % mod;
		}
		base = base * base % mod;
	}
	return ans % mod;
}

ll extended_euclid(ll a,ll b,ll& x,ll& y)  
{  
    ll d = a;  
    if(b){  
        d = extended_euclid(b,a % b,y,x);  
        //printf("before x = %lld y = %lld a = %lld b = %lld\n", x, y, a, b);
        y -= (a / b) * x;  
        //printf("after  x = %lld y = %lld a = %lld b = %lld\n", x, y, a, b);
    }  
    else{    
        x = 1;  
        y = 0;  
    }  
    return d;  
}  
  
void solve(ll a,ll b,ll d,ll& x,ll& y)  
{  
    ll gcd = extended_euclid(a,b,x,y);
    x *= d / gcd;  
    ll t = b / gcd;  
    x = (x % t + t) % t;  
    y=(d - a * x) / b;  
}  
  
int main(){
	ll n, m, x, y, s1_gr_s2 = 0;
	int s1[maxn], s2[maxn];
	cin>>n>>m;
	for (ll i=0; i<n; i++){
		scanf("%d", &s1[i]);
	}
	for (ll i=0; i<n; i++){
		scanf("%d", &s2[i]);
	}

	for (ll i=0; i<n; i++){	

		if (s1[i] == 0){

			if (s2[i] == 0) {
				da = ( ((da * m % mod) * m) % mod + ((m*(m-1)/2 % mod) * deng) % mod) % mod;
				//if (n == 99999 && (i == 0 || i==1 || i==3)) printf("zongshu = %lld da = %lld\n", zongshu, da); 
				zongshu = (((zongshu * m) % mod) * m) % mod;
				deng = deng * m % mod;
				continue;
			}

			zongshu = zongshu * m % mod;

			da = (da*m % mod  + deng * (m-s2[i]) % mod) % mod;
			continue;
		}
		
		if (s2[i] == 0){
			da = (da * m % mod + deng * (s1[i]-1) % mod) % mod;
			zongshu = zongshu * m % mod;
			continue;
		}

		if (s1[i] > s2[i]) {
			da = (da + deng) % mod;
			break;
		}
		if (s1[i] < s2[i]){
			if (!da) {
				cout<<0<<endl;
				return 0;
			}
			break;	
		}
	}
	//da * ans + mod *y = 1;
	
	/*for (int i=2; i<=1e5; i++){
		while (!da%i && !zongshu%i){
			da/=i; zongshu/=i;
		}
	}*/
	ll ans = inv(zongshu) * da % mod;
    cout<<ans<<endl;    
   
    return 0;  

}
可以了 还是很菜啊啊啊啊啊


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值