A
\(\quad\)简单题,看清题意乱搞就可以了。
code
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<climits>
#include<sstream>
#include<fstream>
using namespace std;
#define int long long
signed main()
{
int n;
cin >> n;
int a = 3 , b = 5;
int ca = 1 , cb = 1;
while(b <= n)
{
cb++;
b *= 5;
}
while(a <= n)
{
while(a + b > n && cb > 1)
{
cb--;
b /= 5;
}
if(a + b == n)
{
cout << ca << " " << cb;
return 0;
}
a *= 3;
ca++;
b *= 5;
cb++;
}
cout << -1;
return 0;
}
B
\(\quad\)考虑到一个连通块内的节点数值可以相互转移,所以用并查集弄弄就好了。
code
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<climits>
#include<sstream>
#include<fstream>
using namespace std;
#define int long long
const int N = 2e5 + 10;
int fa[N];
inline int find(int x)
{
if(x == fa[x])
{
return fa[x];
}
else
{
return fa[x] = find(fa[x]);
}
}
inline void modify(int x , int y)
{
int p = find(x) , q = find(y);
fa[p] = q;
}
int a[N] , b[N];
int sa[N] , sb[N];
signed main()
{
ios::sync_with_stdio(false);
int n , m;
cin >> n >> m;
for(register int i = 1 ; i <= n ; i++)
{
cin >> a[i];
}
for(register int i = 1 ; i <= n ; i++)
{
cin >> b[i];
}
for(register int i = 1 ; i <= n ; i++)
{
fa[i] = i;
}
for(register int i = 1 ; i <= m ; i++)
{
int u , v;
cin >> u >> v;
modify(u , v);
}
for(register int i = 1 ; i <= n ; i++)
{
sa[find(i)] += a[i];
sb[find(i)] += b[i];
}
for(register int i = 1 ; i <= n ; i++)
{
if(sa[i] != sb[i])
{
cout << "No";
return 0;
}
}
cout << "Yes";
return 0;
}
C题题目太常生肉看不懂就走去搞其它的了。