2020牛客暑期多校训练营(第二场)

B.Boundary(数学)
以一个点为基础,暴力枚举另外一个点就可以,就是算圆心的时候有点废手。。。
AC代码

#include 
inline long long read(){char c = getchar();long long x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 2e6 + 5;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
const int mod = 998244353;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
map<pair<double,double>,ll> mp;
ll Max;
void solve(double x1,double y1,double x2,double y2,double x3,double y3)
{
    double k = (2*(x2-x1)*2*(y3-y2))-(2*(x3-x2)*2*(y2-y1));
    double numx = ((x2*x2+y2*y2-x1*x1-y1*y1)*(2*(y3-y2))) - ((x3*x3+y3*y3-x2*x2-y2*y2)*(2*(y2-y1)));
    double numy = ((2*(x2-x1)*(x3*x3+y3*y3-x2*x2-y2*y2))) - ((2*(x3-x2))*(x2*x2+y2*y2-x1*x1-y1-y1));
    numx /= k,numy /= k;
    mp[{numx,numy}]++;
    Max = max(Max,mp[{numx,numy}]);
}
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
    int n;
    cin >> n;
    double x[n+5],y[n+5];
    for(int i = 0;i < n;i++)
        cin >> x[i] >> y[i];
    for(int i = 0;i < n;i++)
    {
        mp.clear();
        for(int j = i+1;j < n;j++)
        {
            if(x[i]*y[j] == x[j]*y[i]) continue;
            solve(0.0,0.0,x[i],y[i],x[j],y[j]);
        }
    }
    cout << Max+1 << endl;
}

C.Cover the Tree(dfs序)
首先得明白题意,所谓的连一条链所覆盖的边,是指U 到 V 的最短通路。
那么很显然是从叶子节点入手连链,但是就要想到分配问题,这里我们利用dfs序来进行连边

AC代码

#include 
inline long long read(){char c = getchar();long long x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 2e5 + 5;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
const int mod = 1e9+7;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
vector<int> v[N];
int arr[N],ans;
void dfs(int a,int b)
{
    if(v[a].size() == 1)
    {
        arr[++ans] = a;
        return ;
    }
    for(int i = 0;i < v[a].size();i++)
    {
        if(v[a][i] == b) continue;
        dfs(v[a][i],a);
    }
}
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
    int n,Root = 0;
    cin >> n;
    for(int i = 0;i < n-1;i++)
    {
        int a,b;
        cin >> a >> b;
        if(!Root) Root = a;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(int i = 1;i <= n;i++)
        if(v[i].size() > 1)
            {Root = i;break;}//找到一个非叶子节点进行dfs
    dfs(Root,0);
    cout << (ans+1)/2 << endl;
    for(int i = 1;i <= (ans+1)/2;i++)
        cout << arr[i] << " " << arr[i+ans/2] << endl;//连链分配
}

D.Duration
水题:

#include 
inline long long read(){char c = getchar();long long x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 1e5 + 10;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
const int mod = 1e9+7;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
    int a,b,c;
    int e,f,g;
    char d;
    scanf("%d%c%d%c%d",&a,&d,&b,&d,&c);
    scanf("%d%c%d%c%d",&e,&d,&f,&d,&g);
    ll num1 = a*60*60+b*60+c;
    ll num2 = e*60*60+f*60+g;
    printf("%lld\n",abs(num2-num1));
}

F.Fake Maxpooling
单独写的博客

你可能感兴趣的:(牛客)