Cf #254 (Div. 2)

Source: Internet
Author: User
Tags mul

Question

#include<stdio.h>#include<string.h>char c[101][101];int main(){    long n,m,i,j;    scanf("%ld%ld",&n,&m);    gets(c[0]);    for(i=1;i<=n;i++)        gets(c[i]);    for(i=1;i<=n;i++)        {            for(j=0;j<m;j++)                if(c[i][j]==‘-‘)                    printf("-");                else                {                    if((i%2)^(j%2))                        printf("W");                    else                        printf("B");                }            printf("\n");        }    return 0;}
View code

Question B is that the number of nodes in each China Unicom is reduced by 1, DFS, and query set.

#include <iostream>#include <stdio.h>#include <math.h>#include <string.h>using namespace std;int p[100];int n, m;int find(int x) {    int s;    for(s = x; p[s] >= 0; s = p[s]);    while(s != x)     {        int tmp = p[x];        p[x] = s;        x = tmp;    }    return s;}int unionSet(int a, int b) {    int t1 = find(a);    int t2 = find(b);    int tmp = p[t1] + p[t2];    if(p[t1] > p[t2])     {        p[t1] = t2;        p[t2] = tmp;    }    else     {        p[t2] = t1;        p[t1] = tmp;    }}int main() {    while(scanf("%d%d", &n, &m) != EOF)     {        int a, b;        for(int i = 0; i <= n; i++)         {            p[i] = -1;        }        for(int i = 0; i < m; i++)         {            scanf("%d%d", &a, &b);            int r1 = find(a);            int r2 = find(b);            if(r1 != r2)             {                unionSet(a, b);            }        }        int mul = 0;        for(int i = 1; i <= n; i++)         {            if(p[i] < 0)             {                mul -= (p[i]+1);            }        }        __int64 ans = pow(2.0, mul);                printf("%I64d\n", ans);    }    return 0;}
View code

Question C: minimum density subgraph. I thought about it when I learned the maximum density subgraph at that time. It is actually a side with two points, because the density after adding an edge is smaller than the largest of the two parts.

#include <stdio.h>int n,m;double vval[550],eval[500000];int main(){    double ans=0;    int i,j,u,v;    scanf("%d%d",&n,&m);    for(i=1;i<=n;i++) scanf("%lf",&vval[i]);    for(i=1;i<=m;i++)    {        scanf("%d%d%lf",&u,&v,&eval[i]);        if((vval[u]+vval[v])/eval[i]>ans)            ans=(vval[u]+vval[v])/eval[i];    }    printf("%.9lf\n",ans);    return 0;}
View code

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.