判正误
这题数据水到爆炸啊用一个pow竟然就能过。我用快速幂咋整都过不了当场心态炸裂
#include <bits/stdc++.h>///为啥快速幂过不了哪?
using namespace std;
int main()
{
int T;
scanf("%d",&T);
long long a,b,c,d,e,f,g;
while(T--){
scanf("%lld%lld%lld%lld%lld%lld%lld",&a,&b,&c,&d,&e,&f,&g);
long long sum1,sum2,sum3;
sum1 = pow(a,d);
sum2 = pow(b,e);
sum3 = pow(c,f);
printf("%s\n",sum1 + sum2 + sum3 == g ? "Yes" : "No");
}
}
/*
*/
赛后题解出来了本题实际上想考察这个:
a^d + b^e + c^f 同余g(mod M)。表示并不晓得这个东西。而且这个关系只是概率成立so MOD的值最好多取一些。
正确代码如下:
#include <bits/stdc++.h>///为啥快速幂过不了哪?
using namespace std;
const int MOD = 1e9 + 7;
long long pown(long long a,long long k)
{
long long ans = 1;
while(k)
{
if(k&1) ans = ans * a % MOD;
k >>= 1;
a = a * a % MOD;
}
return ans;
}
int main()
{
int T;
scanf("%d",&T);
long long a,b,c,d,e,f,g;
while(T--){
scanf("%lld%lld%lld%lld%lld%lld%lld",&a,&b,&c,&d,&e,&f,&g);
long long sum1,sum2,sum3;
sum1 = pown(a,d);
sum2 = pown(b,e);
sum3 = pown(c,f);
printf("%s\n",sum1 + sum2 + sum3 == g % MOD ? "Yes" : "No");
}
}
/*
*/
其实就是在我WA掉的代码上多MOD一下,这个MOD的值是我用现成的估计某些人肯定被这个搞过。比如这位大佬的代码
(参考ID VibrantY)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll qpow(ll base, ll n, ll Mod){
ll ans = 1;
while(n){
if(n & 1) ans = ans * base % Mod;
base = base * base % Mod;
n >>= 1;
}
return ans;
}
ll p[1000] = {1000000007, 1000000009, 1000000021, 1000000033, 1000000087, 1000000093, 1000000097, 1000000103, 1000000123, 1000000181, 1000000207, 1000000223, 1000000241, 1000000271, 1000000289, 1000000297, 1000000321, 1000000349, 1000000363, 1000000403, 1000000409, 1000000411, 1000000427, 1000000433, 1000000439, 1000000447, 1000000453, 1000000459, 1000000483, 1000000513, 1000000531, 1000000579, 1000000607, 1000000613, 1000000637, 1000000663, 1000000711, 1000000753, 1000000787, 1000000801, 1000000829, 1000000861, 1000000871, 1000000891, 1000000901, 1000000919, 1000000931, 1000000933, 1000000993, 1000001011, 1000001021, 1000001053, 1000001087, 1000001099, 1000001137, 1000001161, 1000001203, 1000001213, 1000001237, 1000001263, 1000001269, 1000001273, 1000001279, 1000001311, 1000001329, 1000001333, 1000001351, 1000001371, 1000001393, 1000001413, 1000001447, 1000001449, 1000001491, 1000001501, 1000001531, 1000001537, 1000001539, 1000001581, 1000001617, 1000001621, 1000001633, 1000001647, 1000001663, 1000001677, 1000001699, 1000001759, 1000001773, 1000001789, 1000001791, 1000001801, 1000001803, 1000001819, 1000001857, 1000001887, 1000001917, 1000001927, 1000001957, 1000001963, 1000001969, 1000002043, 1000002089, 1000002103, 1000002139, 1000002149, 1000002161, 1000002173, 1000002187, 1000002193, 1000002233, 1000002239, 1000002277, 1000002307, 1000002359, 1000002361, 1000002431, 1000002449, 1000002457, 1000002499, 1000002571, 1000002581, 1000002607, 1000002631, 1000002637, 1000002649, 1000002667, 1000002727, 1000002791, 1000002803, 1000002821, 1000002823, 1000002827, 1000002907, 1000002937, 1000002989, 1000003009, 1000003013, 1000003051, 1000003057, 1000003097, 1000003111, 1000003133, 1000003153, 1000003157, 1000003163, 1000003211, 1000003241, 1000003247, 1000003253, 1000003267, 1000003271, 1000003273, 1000003283, 1000003309, 1000003337, 1000003351, 1000003357, 1000003373, 1000003379, 1000003397, 1000003469, 1000003471, 1000003513, 1000003519, 1000003559, 1000003577, 1000003579, 1000003601, 1000003621, 1000003643, 1000003651, 1000003663, 1000003679, 1000003709, 1000003747, 1000003751, 1000003769, 1000003777, 1000003787, 1000003793, 1000003843, 1000003853, 1000003871, 1000003889, 1000003891, 1000003909, 1000003919, 1000003931, 1000003951, 1000003957, 1000003967, 1000003987, 1000003999, 1000004023, 1000004059, 1000004099, 1000004119, 1000004123, 1000004207, 1000004233, 1000004249, 1000004251, 1000004263, 1000004321, 1000004329, 1000004381, 1000004389, 1000004437, 1000004449, 1000004459, 1000004497, 1000004507, 1000004519, 1000004539, 1000004567, 1000004569, 1000004581, 1000004609, 1000004611, 1000004627, 1000004633, 1000004647, 1000004693, 1000004699, 1000004717, 1000004771, 1000004777, 1000004783, 1000004791, 1000004807, 1000004839, 1000004843, 1000004849, 1000004857, 1000004867, 1000004869, 1000004891, 1000004893, 1000004897, 1000004927, 1000004933, 1000004977, 1000004981, 1000005001, 1000005029, 1000005053, 1000005067, 1000005103, 1000005133, 1000005187, 1000005197, 1000005203, 1000005233, 1000005277, 1000005287, 1000005299, 1000005317, 1000005329, 1000005341, 1000005353, 1000005361, 1000005403, 1000005407, 1000005437, 1000005443, 1000005449, 1000005451, 1000005469, 1000005491, 1000005527, 1000005541, 1000005547, 1000005583, 1000005631, 1000005647, 1000005683, 1000005731, 1000005737, 1000005751, 1000005763, 1000005791, 1000005823, 1000005827, 1000005833, 1000005847, 1000005863, 1000005899, 1000005907, 1000005947, 1000005953, 1000005959, 1000005971, 1000005973, 1000005991, 1000005997, 1000006019, 1000006027, 1000006037, 1000006039, 1000006061, 1000006093, 1000006099, 1000006127, 1000006129, 1000006177, 1000006193, 1000006211, 1000006223, 1000006229, 1000006307, 1000006313, 1000006331, 1000006349, 1000006379, 1000006393, 1000006417, 1000006421, 1000006457, 1000006459, 1000006477, 1000006541, 1000006571, 1000006577, 1000006583, 1000006607, 1000006621, 1000006661, 1000006663, 1000006697, 1000006717, 1000006751, 1000006781, 1000006837, 1000006867, 1000006901, 1000006957, 1000006961, 1000006967, 1000006981, 1000007003, 1000007023, 1000007027, 1000007089, 1000007117, 1000007137, 1000007147, 1000007159, 1000007191, 1000007209, 1000007237, 1000007243, 1000007257, 1000007279, 1000007321, 1000007347, 1000007383, 1000007389, 1000007417, 1000007429, 1000007447, 1000007453, 1000007467, 1000007479, 1000007497, 1000007513, 1000007521, 1000007531, 1000007537, 1000007557, 1000007633, 1000007647, 1000007651, 1000007653, 1000007681, 1000007707, 1000007719, 1000007741, 1000007759, 1000007773, 1000007803, 1000007819, 1000007837, 1000007873, 1000007887, 1000007909, 1000007923, 1000007927, 1000007929, 1000007941, 1000008041, 1000008083, 1000008089, 1000008101, 1000008109, 1000008127, 1000008173, 1000008181, 1000008223, 1000008257, 1000008259, 1000008271, 1000008277, 1000008311, 1000008313, 1000008343, 1000008349, 1000008397, 1000008403, 1000008419, 1000008431, 1000008439, 1000008487, 1000008511, 1000008557, 1000008593, 1000008617, 1000008637, 1000008649, 1000008661, 1000008671, 1000008679, 1000008719, 1000008727, 1000008761, 1000008773, 1000008791, 1000008797, 1000008803, 1000008811, 1000008829, 1000008853, 1000008899, 1000008917, 1000008937, 1000008967, 1000009009, 1000009013, 1000009063, 1000009081, 1000009093, 1000009099, 1000009123, 1000009133, 1000009163, 1000009183, 1000009211, 1000009223, 1000009259, 1000009277, 1000009279, 1000009289, 1000009301, 1000009321, 1000009331, 1000009363, 1000009399, 1000009403, 1000009421, 1000009441, 1000009457, 1000009469, 1000009487, 1000009519, 1000009529, 1000009531, 1000009541, 1000009559, 1000009561, 1000009567, 1000009573, 1000009579, 1000009597, 1000009601, 1000009609, 1000009631, 1000009651, 1000009667, 1000009679, 1000009711, 1000009733, 1000009739, 1000009757, 1000009789, 1000009831, 1000009859, 1000009867, 1000009961, 1000009999, 1000010029, 1000010051, 1000010069, 1000010101, 1000010153, 1000010173, 1000010189, 1000010197, 1000010233, 1000010243, 1000010251, 1000010267, 1000010281, 1000010303, 1000010321, 1000010327, 1000010351, 1000010357, 1000010381, 1000010449, 1000010467, 1000010483, 1000010503, 1000010513, 1000010549, 1000010593, 1000010597, 1000010611, 1000010633, 1000010659, 1000010699, 1000010707, 1000010723, 1000010747, 1000010749, 1000010761, 1000010773, 1000010777, 1000010801, 1000010833, 1000010903, 1000010953, 1000010969, 1000010971, 1000010981, 1000010987, 1000011007, 1000011011, 1000011071, 1000011083, 1000011091, 1000011107, 1000011109, 1000011137, 1000011149, 1000011161, 1000011223, 1000011239, 1000011253, 1000011269, 1000011277, 1000011283, 1000011289, 1000011301, 1000011317, 1000011329, 1000011371, 1000011377, 1000011391, 1000011421, 1000011479, 1000011487, 1000011497, 1000011517, 1000011533, 1000011539, 1000011559, 1000011583, 1000011601, 1000011619, 1000011631, 1000011659, 1000011673, 1000011679, 1000011707, 1000011763, 1000011767, 1000011769, 1000011773, 1000011799, 1000011811, 1000011821, 1000011823, 1000011847, 1000011869, 1000011967, 1000011983, 1000011989, 1000012019, 1000012037, 1000012121, 1000012157, 1000012177, 1000012187, 1000012217, 1000012219, 1000012231, 1000012241, 1000012253, 1000012297, 1000012309, 1000012333, 1000012337, 1000012339, 1000012361, 1000012367, 1000012399, 1000012411, 1000012459, 1000012463, 1000012483, 1000012501, 1000012513, 1000012523, 1000012547, 1000012553, 1000012577, 1000012609, 1000012631, 1000012649, 1000012679, 1000012681, 1000012703, 1000012723, 1000012733, 1000012747, 1000012753, 1000012759, 1000012799, 1000012847, 1000012877, 1000012891, 1000012901, 1000012903, 1000012927, 1000012939, 1000012963, 1000013011, 1000013017, 1000013029, 1000013039, 1000013081, 1000013087, 1000013089, 1000013101, 1000013107, 1000013137, 1000013141, 1000013143, 1000013153, 1000013191, 1000013207, 1000013213, 1000013237, 1000013323, 1000013369, 1000013419, 1000013437, 1000013447, 1000013477, 1000013519, 1000013537, 1000013561, 1000013563, 1000013587, 1000013591, 1000013723, 1000013741, 1000013759, 1000013789, 1000013801, 1000013857, 1000013881, 1000013897, 1000013921, 1000013923, 1000013939, 1000013999, 1000014011, 1000014073, 1000014077, 1000014083, 1000014097, 1000014121, 1000014131, 1000014143, 1000014157, 1000014161, 1000014167, 1000014181, 1000014193, 1000014209, 1000014241, 1000014259, 1000014271, 1000014293, 1000014361, 1000014391, 1000014397, 1000014437, 1000014529, 1000014551, 1000014581, 1000014583, 1000014599, 1000014607, 1000014611, 1000014643, 1000014727, 1000014761, 1000014773, 1000014779, 1000014791, 1000014823, 1000014853, 1000014881, 1000014889, 1000014901, 1000014931, 1000014937, 1000014997, 1000015031, 1000015043, 1000015057, 1000015063, 1000015069, 1000015097, 1000015103, 1000015109, 1000015117, 1000015141, 1000015147, 1000015187, 1000015199, 1000015217, 1000015231, 1000015253, 1000015271, 1000015279, 1000015283, 1000015307, 1000015339, 1000015349, 1000015351, 1000015363, 1000015369, 1000015409, 1000015427, 1000015447, 1000015477, 1000015487, 1000015553, 1000015579, 1000015591, 1000015649, 1000015651, 1000015673, 1000015693, 1000015703, 1000015717, 1000015727, 1000015747, 1000015799, 1000015811, 1000015823, 1000015859, 1000015889, 1000015963, 1000015981, 1000016009, 1000016021, 1000016029, 1000016047, 1000016063, 1000016089, 1000016093, 1000016107, 1000016153, 1000016167, 1000016191, 1000016201, 1000016231, 1000016233, 1000016261, 1000016267, 1000016273, 1000016317, 1000016323, 1000016411, 1000016419, 1000016431, 1000016489, 1000016491, 1000016513, 1000016539, 1000016617, 1000016621, 1000016623, 1000016627, 1000016651, 1000016659, 1000016671, 1000016711, 1000016863, 1000016887, 1000016909, 1000016929, 1000016939, 1000017047, 1000017071, 1000017077, 1000017089, 1000017097, 1000017107, 1000017119, 1000017131, 1000017157, 1000017169, 1000017199, 1000017203, 1000017223, 1000017229, 1000017247, 1000017257, 1000017259, 1000017287, 1000017289, 1000017301, 1000017307, 1000017311, 1000017349, 1000017379, 1000017413, 1000017433, 1000017493, 1000017541, 1000017559, 1000017563, 1000017607, 1000017631, 1000017659, 1000017737, 1000017751, 1000017769, 1000017773, 1000017793, 1000017797, 1000017829, 1000017841, 1000017853, 1000017869, 1000017881, 1000017923, 1000017929, 1000017959, 1000017961, 1000018001, 1000018007, 1000018067, 1000018073, 1000018087, 1000018093, 1000018141, 1000018147, 1000018169, 1000018171, 1000018189, 1000018321, 1000018333, 1000018337, 1000018361, 1000018373, 1000018379, 1000018381, 1000018391, 1000018427, 1000018433, 1000018441, 1000018471, 1000018477, 1000018519, 1000018531, 1000018543, 1000018549, 1000018601, 1000018603, 1000018619, 1000018627, 1000018651, 1000018709, 1000018711, 1000018753, 1000018757, 1000018813, 1000018819, 1000018841, 1000018847, 1000018871, 1000018913, 1000018927, 1000018939, 1000018967, 1000018969, 1000019003, 1000019057, 1000019071, 1000019081, 1000019089, 1000019099, 1000019107, 1000019113, 1000019117, 1000019123, 1000019131, 1000019159, 1000019161, 1000019227, 1000019249, 1000019257, 1000019327, 1000019333, 1000019351, 1000019353, 1000019357, 1000019393, 1000019399, 1000019401, 1000019429, 1000019443, 1000019459, 1000019467, 1000019491, 1000019563, 1000019569, 1000019591, 1000019597, 1000019617, 1000019621, 1000019659, 1000019677, 1000019681, 1000019693, 1000019707, 1000019711, 1000019719, 1000019743, 1000019767, 1000019777, 1000019791, 1000019803, 1000019819, 1000019857, 1000019861, 1000019863, 1000019869, 1000019873, 1000019897, 1000019899, 1000019903, 1000019927, 1000019981, 1000020001, 1000020011, 1000020023, 1000020029, 1000020107, 1000020139, 1000020163, 1000020193, 1000020209, 1000020221, 1000020283, 1000020313, 1000020319, 1000020337, 1000020347, 1000020353, 1000020361, 1000020367, 1000020383, 1000020409, 1000020443, 1000020491, 1000020523, 1000020547, 1000020569, 1000020577, 1000020689, 1000020701, 1000020727, 1000020737, 1000020743, 1000020757, 1000020779, 1000020799, 1000020803, 1000020817, 1000020829, 1000020851, 1000020881, 1000020893, 1000020919, 1000020929};
void solve(){
ll a, b, c, d, e, f, g, gg;
scanf("%lld%lld%lld%lld%lld%lld%lld", &a, &b, &c, &d, &e, &f, &g);
bool flag = true;
for(int i = 0; i < 1000; i++){
ll ans = 0, Mod = p[i];
ans = (ans + qpow((a + Mod) % Mod, d, Mod)) % Mod;
ans = (ans + qpow((b + Mod) % Mod, e, Mod)) % Mod;
ans = (ans + qpow((c + Mod) % Mod, f, Mod)) % Mod;
gg = (g + Mod) % Mod;
flag = (ans == gg);
if(!flag) {
printf("No\n");
return;
}
}
printf("Yes\n");
}
int main(){
int T; scanf("%d", &T);
while(T--) solve();
}
看到这1000的p数组就晓得这肯定是个狠人。
其实,我在比赛时就想过取模这个问题,毕竟数据范围给的太吓人了,我还在纸上试了一下同时取模答案有没有影响但是和上面说的一样同时取模得到的结果只能是g的同余数例如:1 % 3 + 4 % 3 = g % 3
这里的g值可以是11,14等等只要mod 3 = 2就可。但是题目只要求搞一个yes or no出来,只要这个mod够大就不成问题。试一下海阔天空,总比我不服气交六次结果WA六次强。
数三角
话说这次比赛题目名称很有小学数学题的感觉啊。。。
这题是比赛快结束才A的(我可以说主要原因是因为上面那个题错太多搞得我不想看题吗?)中途出去补充了点食物,嘿嘿。
代码:
#include <bits/stdc++.h>
using namespace std;
struct node
{
int x,y;
}p[510];
int main()
{
int n;
int sum = 0;
scanf("%d",&n);
for(int i = 0;i < n;++i) {
scanf("%d%d",&p[i].x,&p[i].y);
}
for(int i = 0;i < n;++i){
for(int j = i + 1;j < n;++j){
for(int k = j + 1;k < n;++k){
long long a = (p[i].x - p[j].x) * (p[i].x - p[j].x) + (p[i].y - p[j].y) * (p[i].y - p[j].y);
long long b = (p[i].x - p[k].x) * (p[i].x - p[k].x) + (p[i].y - p[k].y) * (p[i].y - p[k].y);
long long c = (p[j].x - p[k].x) * (p[j].x - p[k].x) + (p[j].y - p[k].y) * (p[j].y - p[k].y);
//printf("%d %d %d\n",p[i].x,p[i].y,p[j].y);
double t1,t2;
int flag = 0;
t1 = (1.0 * (p[i].y - p[j].y)) / (1.0 * (p[i].x - p[j].x));
t2 = (1.0 * (p[i].y - p[k].y)) / (1.0 * (p[i].x - p[k].x));
//printf("%f %f\n",t1,t2);
if(fabs(t1 - t2) < 0.00000001) flag = 1;
if((!flag)&&(a + b < c||b + c < a||a + c < b)) sum++;
}
}
}
printf("%d\n",sum);
}
/*
10
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
0 0
*/
这题一开始不做是被计算几何这种嘘头吓着的,后来不做是心态炸了。鬼知道是什么我敢交n^3复杂度的代码。不过还是WA掉了两次。
首先,我没考虑三点共线的情况。当我补上三点共线兴高采烈交上去是它又WA了!!这次原因是类型转换t1 = (1.0 * (p[i].y - p[j].y)) / (1.0 * (p[i].x - p[j].x));
。就这玩意儿,1.0要包含括号我可记得了。还有一个注意的地方就是if(fabs(t1 - t2) < 0.00000001)
double类型不能直接判等,要加精度。
做计数
这题没啥说的,我太菜了。为啥别人找的规律总是o(n)就能跑完,我的规律要跑超高复杂度呢。
错误代码
#include <bits/stdc++.h>
using namespace std;
const int MAX = 0x3f3f3f3f;
int main()
{
int n;
int sum = 0;
scanf("%d",&n);
for(int i = 1;pow(i,2) <= n;++i){
for(int j = i;j <= n / i;++j){
int temp = i * j;
int m = sqrt(temp);
if(m * m == temp){
if(i == j) sum++;
else sum+=2;
}
}
}
printf("%d\n",sum);
}
O(n^2)致命。其实赛后我又交了一次结果莫名卡过,赛前记录用时是1001ms就差1ms哎。。。
正确代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,ans;
ans = 0;
scanf("%d",&n);
for(int i = 1;i * i <= n;++i){
int k = i * i;
for(int j = 1;j <= i;++j){
if(j == i) ans++;
else if(k % j == 0) ans += 2;
}
}
printf("%d\n",ans);
}
思路的话就像是我的逆思路,我是从因子i,j入手,这个是从平方数入手。题解上说只要找平方数是O(n^1/2),找平方数的因子数也是O(n ^ 1/2),就可以了。我是真的菜。
看别人代码后发现还有大佬用lct树,表示一个菜鸡并不晓得这是啥玩意。