codeforces#254DIV2解题报告

今天简直大爆发啊。。。吃了顿烧烤居然这么管事。。。。。本弱渣居然做出来了3道,而且B题是我第一次在CF中用到算法。。(以前最多也就是贪心。。。)。

题目地址:codeforces#225

A题:

水题。。不解释。。5分钟1Y。

代码如下:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include<algorithm>

using namespace std;
int main()
{
    int n, m, i, j;
    char s[200][200];
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
    {
        scanf("%s",s[i]);
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if(s[i][j]=='-')
                {
                    printf("-");
                    continue ;
                }
            if((i+j)%2)
                {
                    printf("B");

                }
                else
                    printf("W");
        }
        printf("\n");
    }
    return 0;
}

B题:

这题第一次在CF中使用算法,刚开始还犹豫了一段时间,因为没见过在B题中就用到算法的,后来还是大胆的用上了。。。而且还是并查集。。这题就是把可以反应的药品用并查集放在一块,这样分成了可以互不反应的几个集合,这样的话,最少不能反应的就是每个集合放进去的第一个,剩下的就是最多可以发生反应的药品数量,把数量求出来,假设是n,再求2^n即可。注意要用int64,第一次因为这个错了一次。。不然就能进前100了。。。sad。。

代码如下:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include<algorithm>

using namespace std;
int bin[100];
int find1(int x)
{
    return bin[x]==x?x:bin[x]=find1(bin[x]);
}
void merge1(int x, int y)
{
    int f1, f2;
    f1=find1(x);
    f2=find1(y);
    if(f1!=f2)
    {
        if(f2>f1)
            bin[f2]=f1;
        else
            bin[f1]=f2;
    }
}
int main()
{
    int n, m, i, j, a[100], x, y, b[100], z, num, nn;
    __int64 s=1;
    scanf("%d%d",&n,&m);
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    for(i=1;i<=n;i++)
        bin[i]=i;
        num=0;
        nn=0;
    while(m--)
    {
        scanf("%d%d",&x,&y);
        merge1(x,y);
        a[x]++;
        a[y]++;
    }
    for(i=1;i<=n;i++)
    {
        if(a[i])
        {
            z=find1(i);
            b[z]++;
            num++;
        }
    }
    for(i=1;i<=n;i++)
    {
        if(b[i])
        {
            nn++;
        }
    }
    z=num-nn;
    //printf("%d %d\n",num,nn);
    for(i=1;i<=z;i++)
    {
        s*=2;
    }
    printf("%I64d\n",s);
    return 0;
}

C题:

这题还是很有意思的。。第一次看完以为是什么最大密度子图,因为最近刷网络流,网络流的最小割可以求最大密度子图,但是还没学。。。。我还百度看了一会儿。。。后来想到可以贪心,先把两个点与相连的边值之比的最大值求出来,然后依次向外扩充,这样肯定可行,但是感觉很麻烦。。而且复杂度有点悬。。。但还是硬着头皮写了,然后当写完最大的那一边二点的值时,突然发现再往后扩充肯定越来越小。。。然后自己YY了一下证明。。这样是可以证明的,于是果断提交,1Y~

代码如下:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include<algorithm>

using namespace std;
int main()
{
    int n, m, i, p[600], u, v, w;
    double max1=0, x;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)
        scanf("%d",&p[i]);
    while(m--)
    {
        scanf("%d%d%d",&u, &v,&w);
        x=(p[u]+p[v])*1.0/w;
        if(max1<x)
        {
            max1=x;
        }
    }
    printf("%.15lf\n",max1);
    return 0;
}

codeforces#254DIV2解题报告

时间: 2024-07-30 09:17:11

codeforces#254DIV2解题报告的相关文章

解题报告 之 CodeForces 91B Queue

解题报告 之 CodeForces 91B Queue Description There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue.

codeforces 505A. Mr. Kitayuta&#39;s Gift 解题报告

题目链接:http://codeforces.com/problemset/problem/505/A 题目意思:给出一个长度不大于10的小写英文字符串 s,问是否能通过在字符串的某个位置插入一个字母,使得新得到的字符串成为回文串. /**************************************(又到自我反省时刻) 做的时候,通过添加一个单位使得长度增加1,找出中点,检验前一半的位置,找出对称位置替换成对应的前一半位置的字符,然后原字符串剩下的部分追加到后面,再判断回文.但是由于

Codeforces Round #259 (Div. 2) 解题报告

终于重上DIV1了.... A:在正方形中输出一个菱形 解题代码: 1 // File Name: a.cpp 2 // Author: darkdream 3 // Created Time: 2014年08月01日 星期五 23时27分55秒 4 5 #include<vector> 6 #include<set> 7 #include<deque> 8 #include<stack> 9 #include<bitset> 10 #inclu

codeforces 591A. Wizards&#39; Duel 解题报告

题目链接:http://codeforces.com/problemset/problem/591/A 题目意思:其实看下面这幅图就知道题意了,就是Harry 和 He-Who-Must-Not-Be-Named 分别在走廊末端,各发射自己的impulse,其中Harry 的 impulse 速度为 p 米/s,He-...-Named (这个名字太长,姑且写成这样)为 q米/s.然后相遇之后各自回到它们的主人身边,再发射,问第二次相遇的时候,Harry的impulse 离他的位置距离是多少.

Codeforces 459(#261 (Div. 2) ) 解题报告

A:给你一个正方形的两点,让你求其余亮点 解法:乱搞 解题代码: 1 // File Name: a.cpp 2 // Author: darkdream 3 // Created Time: 2014年08月15日 星期五 23时24分04秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #include<deque> 10 #include<

解题报告 之 CodeForces 6E Exposition

解题报告 之 CodeForces 6E Exposition Description There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction

Codeforces 450(#257 (Div. 2) ) 解题报告

A: 1 // File Name: a.cpp 2 // Author: darkdream 3 // Created Time: 2014年07月19日 星期六 21时01分28秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #include<deque> 10 #include<stack> 11 #include<bits

Codeforces Round #262 (Div. 2)解题报告

详见:http://robotcator.logdown.com/posts/221514-codeforces-round-262-div-2 1:A. Vasya and Socks   http://codeforces.com/contest/460/problem/A 有n双袜子,每天穿一双然后扔掉,每隔m天买一双新袜子,问最多少天后没有袜子穿.. 简单思维题:以前不注重这方面的训练,结果做了比较久,这种题自己边模拟边想.不过要多考虑trick ```c++ int main(){ i

CodeForces 250B Restoring IPv6 解题报告

Description An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example o