# Basic Training Camp for 2020 Niuke Winter Vacation Algorithms 2

##### G. Correct or incorrect judgment:

Coca-Cola has seven integers a, b, c, d, e, f, g a, b, c, d, e, f, g a, b, c, d, e, f, b, d, e, g, and he guess a d+b e+c f=g a^d+b^e+c^f=g a d+b e+c f=g.But Coca-Cola can't do such a huge calculation.
Please verify: Coca-Cola's guess is true.
Input:
The first row has a positive integer TTT, indicating that there is TTT group data.
Each set of data is entered in a row with seven integers a, b, c, d, e, f, g a, b, c, d, e, f, g a, b, c, d, e, e, f, G.
Guarantees that 1 or 1 <1\leq1 <TTT TTT <1000\\leq1000 <1000,,,, 8722;109-10^9 109 < \leq < \leq <a, b, c, g a, c, g a, c, g a, b, b, g a, b, b, c, g a, b, b, c, g, c, g, g, g <\\\\\\\\A zero exponent and zero base occur.
Output:
Output one row for each set of data, if conjecture holds, output YesYesYes, otherwise output NoNoNo No.
Questions:
_obviously can't be calculated directly, it was stuck at that time.If a d+b e+c f=g(mod_M) a^d+b^e+c^f=g(mod\M) a d+b e+c f=g(modM), then the original formula may b e true and the probability can b e increased by taking several modules.But if only M=1e9+7M=1e9+7M=1e9+7M=1e9+7 can pass, I don't know why.This method is first seen in complementing the 2019ec final question, the random number method.I didn't think it would work here.
Code for module 1e9+71e9+71e9+7 only:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll a,b,c,d,e,f,g;
ll power(ll x,ll y)
{
ll res=1;
while(y)
{
if(y&1)
res=res*x%mod;
x=x*x%mod;
y>>=1;
}
return res%mod;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lld%lld%lld%lld%lld%lld%lld",&a,&b,&c,&d,&e,&f,&g);
ll am=power(a,d);
ll bm=power(b,e);
ll cm=power(c,f);
if((am+bm+cm)==g)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}


##### D. Number triangle:

Violence: (Attention to the special judgment that three points are collinear)
O(n3)O(n^3)O(n3)

#include <bits/stdc++.h>
using namespace std;
const int N=550;
typedef long long ll;
ll x[N],y[N];
bool check(int a,int b,int c)
{
if((y[a]-y[b])*(x[c]-x[b])==(y[c]-y[b])*(x[a]-x[b]))
return false;
return true;
}
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lld%lld",&x[i],&y[i]);
if(n<3)
{
printf("0\n");
return 0;
}
ll d[5]={0};
int cnt=0;
for(int i=1;i<=n-2;i++)
{
for(int j=i+1;j<=n-1;j++)
{
for(int k=j+1;k<=n;k++)
{
d[1]=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
d[2]=(x[i]-x[k])*(x[i]-x[k])+(y[i]-y[k])*(y[i]-y[k]);
d[3]=(x[j]-x[k])*(x[j]-x[k])+(y[j]-y[k])*(y[j]-y[k]);
sort(d+1,d+1+3);//cout<<d[1]<<" "<<d[2]<<" "<<d[3]<<endl;
if(d[1]+d[2]<d[3]&&check(i,j,k))
cnt++;
}
}
}
printf("%d\n",cnt);
return 0;
}


##### E. Count:

_When you see the title, you still have questions about the equal sign in the title. If floating point numbers are integers, can't you?I can't tell until I read the solution.That is, what is after the root sign.
The original can be converted to: i+j+2i j=k i+j+2 \sqrt{i j}=k i+j+2i j=k, where i, j, K i, j, K are integers, so i_j i*j i_j must be fully square.So you can O(n)O(\sqrt n)O(n), enumerate the complete square number within n, then O(n)O(\sqrt n)O(n) enumerate the factors of the number, count it, pay attention to weight removal.
Complexity: O(n)O(n)O(n)

#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,cnt=0;
scanf("%d",&n);
for(int i=1;i*i<=n;i++)//Enumerate Complete Squares
{
for(int j=1;j<=i;j++)
if(i*i%j==0)//If it is a factor
cnt+=2;
cnt--;//i=j Repeat
}
printf("%d\n",cnt);
return 0;
}


##### F. Take items:

_This topic is a reminder to write about greed in the future. It cannot be taken for granted that we must seriously consider the criteria of greed and make clear judgments.At first naive thought that cow's selection had a high value and cow's Cola had a high value.But this is not the case if you carefully consider ways to increase the score difference.
_If cattle choose item I I I and Coca-Cola choose item J J j, the score difference between cattle and cattle is (a i_b j) (a_i-b_j) (a i_b j), and after exchange, the score difference after exchange is (a j_b i) (a_j-b_i) (a j_b i).The difference between them is_=(a i+b i_a j_b j)\Delta=(a_i+b_i-a_j-b_j)_=(a i+b I a j_b j). For a cow to have a high score, the_Delta_should be greater than 0, and all items with a higher value (a+b) (a+b) should be selected.The same is true for Coca-Cola.
O(nlogn)O(nlogn)O(nlogn)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int>P;
const int N=2e5+5;
ll a[N],b[N];
P c[N];
vector<int>ans[2];
bool cmp(P x,P y)
{
return x.first>y.first;
}
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lld",&a[i]);
for(int i=1;i<=n;i++)
scanf("%lld",&b[i]);
for(int i=1;i<=n;i++)
{
c[i].second=i;
c[i].first=a[i]+b[i];
}
sort(c+1,c+1+n,cmp);
for(int i=1;i<=n;i++)
{
if(i&1)
ans[0].push_back(c[i].second);
else
ans[1].push_back(c[i].second);
}
printf("%d",ans[0][0]);
for(int i=1;i<ans[0].size();i++)
printf(" %d",ans[0][i]);
printf("\n");
printf("%d",ans[1][0]);
for(int i=1;i<ans[1].size();i++)
printf(" %d",ans[1][i]);
printf("\n");
return 0;
}


106 original articles were published, 11 were praised, and 1728 were visited

Posted by BleedingSky on Thu, 06 Feb 2020 21:19:46 -0800