# 牛客网练习赛 41

A：

#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int a,b;
scanf("%d%d",&a,&b);
if(a != b) puts("No");
else puts("Yes");
}
}

B：

#include <bits/stdc++.h>
using namespace std;
const int tot = 300 * 666;
const int MOD = 1e8+7;
int dp[2][tot*2+1000] , a[333];
int main()
{
int n;
scanf("%d",&n);
int sum = 0;
for(int i = 1 ; i <= n ; i++) scanf("%d",&a[i]) , sum += abs(a[i]);
int k = 0;
dp[0][tot] = 1;
for(int i = 1 ; i <= n ; i++)
{
k = k ^ 1;
for(int j = -tot ; j < tot ; j ++)
{
if(j + tot - a[i] >= 0) dp[k][j+tot] = dp[k^1][j+tot-a[i]];
if(tot - j >= 0) dp[k][j+tot] += dp[k^1][tot-j];
//dp[k][j+tot] = (dp[k^1][j+tot-a[i]] + dp[k^1][tot-j]) % MOD;
dp[k][j+tot] %= MOD;
}
dp[k][tot+666] = 0;
}
cout<<dp[k][tot-666]<<endl;
}


C：

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 1e5+10;
int p[maxn] , ans[maxn] , a[maxn];
int getf(int x)
{
return x == p[x] ? x : p[x] = getf(p[x]);
}
signed main()
{
int n,m,t;
scanf("%d%d",&n,&m);
for(int i = 1 ; i <= n ; i++) p[i] = i;
for(int i = 1 ; i <= n ; i++) scanf("%lld",&a[i]);
for(int i = 1 ; i <= n ; i++)
{
scanf("%lld",&t);
int dx = getf(t);
int dy = getf(i);
if(dx != dy)
{
p[dx] = dy;
}
}
for(int i = 1 ; i <= n ; i++) ans[getf(i)] += a[i];
sort(ans+1,ans+n+1,[](int a,int b){return a > b;});
int ANS = 0;
for(int i = 1 ; i <= m ; i++) ANS += ans[i];
cout<<ANS<<endl;

}


D：

 int v = (u^(1<<j));
if(dis[v] > dis[u] + 1)
{
dis[v] = dis[u] + 1;
Q.push(v);
}

#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 3e5+100;
char ch[maxn][22];
int dis[1<<20];
queue<int>Q;
int main()
{
int n , m;
scanf("%d%d",&n,&m);
for(int i = 0 ; i < (1<<m) ; i++) dis[i] = INF;
for(int i = 0 ; i < n ; i++)
{
cin>>ch[i];
int x = 0;
for(int j = 0 ; j < m ; j++)
{
if(ch[i][j] == '1') x |= (1<<j);
}
dis[x] = 0;
Q.push(x);
}
while(!Q.empty())
{
int u = Q.front();
Q.pop();
for(int j = 0 ; j < m ; j++)
{
int v = (u^(1<<j));
if(dis[v] > dis[u] + 1)
{
dis[v] = dis[u] + 1;
Q.push(v);
}
}
}
int ans = INF;
for(int i = 0 ; i < (1<<m) ; i++) ans = min(ans,m-dis[i]);
cout<<ans<<endl;

}


F：

#include<bits/stdc++.h>
using namespace std;
const int maxn = 105;
const double PI = acos(-1);
typedef struct point {
double x,y,z;
point() {

}
point(double a, double b,double c) {
x = a;
y = b;
z = c;
}
point operator -(const point &b)const {     //·µ»Ø¼õÈ¥ºóµÄÐÂµã
return point(x - b.x, y - b.y,z-b.z);
}
point operator +(const point &b)const {     //·µ»Ø¼ÓÉÏºóµÄÐÂµã
return point(x + b.x, y + b.y,z+b.z);
}
//Êý³Ë¼ÆËã
point operator *(const double &k)const {    //·µ»ØÏà³ËºóµÄÐÂµã
return point(x * k, y * k,z*k);
}
point operator /(const double &k)const {    //·µ»ØÏà³ýºóµÄÐÂµã
return point(x / k, y / k,z/k);
}
double operator *(const point &b)const {    //µã³Ë
return x*b.x + y*b.y+z*b.z;
}
}point;
double dist(point p1, point p2) {       //·µ»ØÆ½ÃæÉÏÁ½µã¾àÀë
return sqrt((p1 - p2)*(p1 - p2));
}
typedef struct sphere {//Çò
double r;
point centre;
}sphere;
double SphereInterVS(sphere a, sphere b) {
double d = dist(a.centre, b.centre);//ÇòÐÄ¾à
double t = (d*d + a.r*a.r - b.r*b.r) / (2.0 * d);//
double h = sqrt((a.r*a.r) - (t*t)) * 2;//h1=h2£¬Çò¹ÚµÄ¸ß
double angle_a = 2 * acos((a.r*a.r + d*d - b.r*b.r) / (2.0 * a.r*d));  //ÓàÏÒ¹«Ê½¼ÆËãr1¶ÔÓ¦Ô²ÐÄ½Ç£¬»¡¶È
double angle_b = 2 * acos((b.r*b.r + d*d - a.r*a.r) / (2.0 * b.r*d));  //ÓàÏÒ¹«Ê½¼ÆËãr2¶ÔÓ¦Ô²ÐÄ½Ç£¬»¡¶È
double l1 = ((a.r*a.r - b.r*b.r) / d + d) / 2;
double l2 = d - l1;
double x1 = a.r - l1, x2 = b.r - l2;//·Ö±ðÎªÁ½¸öÇòÈ±µÄ¸ß¶È
double v1 = PI*x1*x1*(a.r - x1 / 3);//Ïà½»²¿·Ör1Ô²Ëù¶ÔÓ¦µÄÇòÈ±²¿·ÖÌå»ý
double v2 = PI*x2*x2*(b.r - x2 / 3);//Ïà½»²¿·Ör2Ô²Ëù¶ÔÓ¦µÄÇòÈ±²¿·ÖÌå»ý
double  v = v1 + v2;//Ïà½»²¿·ÖÌå»ý
return v;
}

sphere qiu[maxn],s;

int main()
{

int z, CASE = 1;
scanf("%lf%lf%lf%lf",&qiu[0].centre.x,&qiu[0].centre.y,&qiu[0].centre.z,&qiu[0].r);
scanf("%lf%lf%lf%lf",&s.centre.x,&s.centre.y,&s.centre.z,&s.r);
double ans = 0.0;
double V ,S ;
double dis = dist(qiu[0].centre,s.centre);
double p = max(qiu[0].r,s.r);
double q = min(qiu[0].r,s.r);
if(dis >= qiu[0].r + s.r)
{
ans += (4.0/3.0)*PI*qiu[0].r*qiu[0].r*qiu[0].r;
ans += (4.0/3.0)*PI*s.r*s.r*s.r ;
printf("%.7f\n",ans);
}
else if(dis + q <= p || dis + p <= q)
{

ans += (4.0/3.0)*PI*p*p*p;
printf("%.7f\n",ans);
return 0;
}
else
{
ans =  (4.0/3.0)*PI*qiu[0].r*qiu[0].r*qiu[0].r + (4.0/3.0)*PI*s.r*s.r*s.r - SphereInterVS(qiu[0],s);
printf("%.7f\n",ans);
}
}