#include<cstdio>#include<iostream>#include<algorithm>usingnamespace std;voidsolve(){int a, b, c, x, y, z;
cin >> a >> b >> c >> x >> y >> z;longlong ans =(longlong)min(a, y)+min(b, z)+min(c, x);
cout << ans;}intmain(){solve();return0;}
一开始直接百度去了,HDU有道类似的题,代码拿过来改改发现改不对。后来寻思这数据也不大,就暴力
n
3
n^3
n3试试了,就直接枚举任意三个点,这三点能形成钝角三角形的充要条件就是任意一个角是钝角,所以枚举三个点后,可以直接算出三边长,然后余弦定理可以直接判断是否为钝角。
但是这里我T了好多次,我太实诚了,直接把余弦定理的
cos
θ
=
a
2
+
b
2
−
c
2
2
a
b
\cos\theta=\frac{a^2+b^2-c^2}{2ab}
cosθ=2aba2+b2−c2算出来了。。。你想啊,钝角,一定满足
cos
θ
<
0
\cos\theta<0
cosθ<0,也就是
a
2
+
b
2
−
c
2
2
a
b
<
0
\frac{a^2+b^2-c^2}{2ab}<0
2aba2+b2−c2<0,也就是
a
2
+
b
2
<
c
2
a^2+b^2<c^2
a2+b2<c2。所以连开根号都不需要了。以后一定要记得,判断三角形是直角/锐角/钝角,直接用三边关系判断就可以了。
这里提下下怎么判断,有两种方法,一种是用斜率,一种是用面积。斜率就不必说了,这里说一下面积。
S
=
1
2
(
x
1
y
2
+
x
2
y
3
+
x
3
y
1
−
x
2
y
1
−
x
3
y
2
−
x
1
y
3
)
S=\frac{1}{2}( x_1y_2+x_2y_3+x_3y_1-x_2y_1-x_3y_2-x_1y_3)
S=21(x1y2+x2y3+x3y1−x2y1−x3y2−x1y3)(自行加绝对值)
另外这题没有说坐标是整型还是浮点型,所以我用了long double
代码
#pragma GCC optimize(2)#include<iostream>#include<cstdio>#include<cmath>usingnamespace std;longdouble x[600], y[600];voidsolve(){longlong n;
cin >> n;for(longlong i =1; i <= n; i++)
cin >> x[i]>> y[i];longlong ans =0;for(longlong i =1; i <= n; i++)for(longlong j = i +1; j <= n; j++)for(longlong k = j +1; k <= n; k++){longdouble a =(x[i]- x[j])*(x[i]- x[j])+(y[i]- y[j])*(y[i]- y[j]);longdouble b =(x[i]- x[k])*(x[i]- x[k])+(y[i]- y[k])*(y[i]- y[k]);longdouble c =(x[k]- x[j])*(x[k]- x[j])+(y[k]- y[j])*(y[k]- y[j]);if((x[i]* y[j]- x[j]* y[i])+(x[j]* y[k]- x[k]* y[j])+(x[k]* y[i]- y[k]* x[i])==0)continue;if((b + c < a)||(b + a < c)||(a + c < b)) ans++;}
cout << ans;}intmain(){solve();return0;}
我们把原式左右同时平方,得到
i
+
2
i
j
+
j
=
k
i+2\sqrt{ij}+j=k
i+2ij+j=k,那么只要
i
j
ij
ij是完全平方数,那么就一定可以合并。所以就只需要在第一层中枚举所有的完全平放数,第二层里计算一下约数个数就可以了。约数个数其实是可以线筛的,这里暴力就可以。
代码
#include<cstdio>#include<iostream>#include<algorithm>usingnamespace std;intf(int n){int ans =0;for(int i =1; i * i <= n; i++){if(i * i == n){
ans++;break;}int a = i, b = n / i;if(n % a !=0)continue;
ans +=2;}return ans;}voidsolve(){int n;scanf("%d",&n);longlong ans =0;for(int i =1; i <= n; i++){if(i * i > n)break;
ans +=f(i * i);}
cout << ans;}intmain(){solve();return0;}
给定abcdefg,让你验证
a
d
+
b
e
+
c
f
=
g
a^d+b^e+c^f=g
ad+be+cf=g。数据都在1e9
正文
官方题解里说,直接计算会 TLE / MLE ,考虑在模意义下进行计算,若
a
d
+
b
e
+
c
f
≡
g
(
m
o
d
M
)
a^d+b^e+c^f\equiv g \pmod M
ad+be+cf≡g(modM),则原式有概率成立,多选择一些模数以提高正确率。这里具体讲一下,什么时候是对的什么时候不对。
由
a
d
+
b
e
+
c
f
≡
g
(
m
o
d
M
)
a^d+b^e+c^f\equiv g \pmod M
ad+be+cf≡g(modM)可以得
a
d
+
b
e
+
c
f
+
k
M
=
g
a^d+b^e+c^f+kM=g
ad+be+cf+kM=g,也就是
a
d
+
b
e
+
c
f
−
g
=
k
M
a^d+b^e+c^f-g=kM
ad+be+cf−g=kM时,会有误判。但样例就那么多,所以不断改变M的值,就能AC了。
代码
#include<iostream>#include<cstdio>#include<cmath>usingnamespace std;constlonglong mod =1e9+9;longlongksm(longlong a,longlong b){if(a ==0)return0;longlong res =1;while(b ){if(b &1)
res = res * a%mod;
b = b >>1;
a = a * a %mod;}return res;}voidsolve(){//cout << ksm(-2, 3) << endl;int t;
cin >> t;while(t--){longlong a, b, c, d, e, f, g;
cin >> a >> b >> c >> d >> e >> f >> g;longlong x =ksm(a, d);longlong y =ksm(b, e);longlong z =ksm(c, f);longlong ans =(x + y + z + mod)% mod;printf("%s\n", ans ==(g + mod)% mod ?"Yes":"No");}}intmain(){solve();return0;}