2020/07/28(第一次组队赛)

比赛经历

刚参加集训的第二天,已经感受到acm集训队的紧张气氛,昨天晚上参加了个人赛,AC了两道题,今天中午和孔老师and燕大哥参加组队赛,成立了名为y_k_y的队伍就从12:00开始比赛了。比赛和昨天的个人赛一样,全英文的题目,而且可以看到自己队伍的排名,打了一个下午,最终AC了四道题(主要靠孔老师和燕大哥带),第五道差一点做出来(最后都精疲力尽了)。感觉是一个不错的开端。

学到的题目

B题本来想找一个新奇的解题思路,但孔老师直接说可以暴力解决,于是我们开始了暴力解题的征途。
原题:B - Break Standard Weight ZOJ - 3706
The balance was the first mass measuring instrument invented. In its traditional form, it consists of a pivoted horizontal lever of equal length arms, called the beam, with a weighing pan, also called scale, suspended from each arm (which is the origin of the originally plural term “scales” for a weighing instrument). The unknown mass is placed in one pan, and standard masses are added to this or the other pan until the beam is as close to equilibrium as possible. The standard weights used with balances are usually labeled in mass units, which are positive integers.

With some standard weights, we can measure several special masses object exactly, whose weight are also positive integers in mass units. For example, with two standard weights 1 and 5, we can measure the object with mass 1, 4, 5 or 6 exactly.

In the beginning of this problem, there are 2 standard weights, which masses are x and y. You have to choose a standard weight to break it into 2 parts, whose weights are also positive integers in mass units. We assume that there is no mass lost. For example, the origin standard weights are 4 and 9, if you break the second one into 4 and 5, you could measure 7 special masses, which are 1, 3, 4, 5, 8, 9, 13. While if you break the first one into 1 and 3, you could measure 13 special masses, which are 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13! Your task is to find out the maximum number of possible special masses.

Input
There are multiple test cases. The first line of input is an integer T < 500 indicating the number of test cases. Each test case contains 2 integers x and y. 2 ≤ x, y ≤ 100

Output
For each test case, output the maximum number of possible special masses.

Sample Input
2
4 9
10 10
Sample Output
13
9
题目大体意思就是说:先给你天平的两个砝码,其中可以将任意一个砝码再次拆分成两个质量相加等于原砝码质量的小砝码,问这些砝码最大可测量几种不同的质量(整数计算)。
C++代码(比赛时孔老师暴力出来的当时数组开小了导致了一次段错误segment fault)

#include <bits/stdc++.h>
using namespace std;
int main() {
    
    
    ios::sync_with_stdio(false);
    cin.tie();
    cout.tie();
    int t;
    int a, b;
    int i, j;
    int c[50];
    int num[210];
    int numa = 0, numb = 0;
    int maxa = 0, maxb = 0;
    cin >> t;
    while (t--) {
    
    
        maxa = 0, maxb = 0;
        numa = 0, numb = 0;
        cin >> a >> b;
        if (a != b) {
    
    
            for (i = 1; i < a / 2; i++) {
    
    
                memset(num, 0, sizeof(num));
                j = a - i;
                c[0] = i;
                c[1] = j;
                c[2] = b;
                c[3] = abs(i - j);
                c[4] = abs(i - b);
                c[5] = abs(i + j);
                c[6] = abs(i + b);
                c[7] = abs(j + b);
                c[8] = abs(j - b);
                c[9] = abs(i + j + b);
                c[10] = abs(i + j - b);
                c[11] = abs(i - j + b);
                c[12] = abs(i - j - b);
                for (int k = 0; k < 13; k++) {
    
    
                    num[c[k]]++;
                }
                for (int k = 1; k <= 200; k++) {
    
    
                    if (num[k] > 0) numa++;
                }
                if (maxa < numa) maxa = numa;
                numa = 0;
            }
            for (i = 1; i <= b / 2; i++) {
    
    
                memset(num, 0, sizeof(num));
                j = b - i;
                c[0] = i;
                c[1] = j;
                c[2] = a;
                c[3] = abs(i - j);
                c[4] = abs(i - a);
                c[5] = abs(i + j);
                c[6] = abs(i + a);
                c[7] = abs(j + a);
                c[8] = abs(j - a);
                c[9] = abs(i + j + a);
                c[10] = abs(i + j - a);
                c[11] = abs(i - j + a);
                c[12] = abs(i - j - a);
                for (int k = 0; k < 13; k++) {
    
    
                    num[c[k]]++;
                }
                for (int k = 1; k <= 200; k++) {
    
    
                    if (num[k] > 0) numb++;
                }
                if (maxb < numb) maxb = numb;
                numb = 0;
            }
            if (maxa > maxb)
                cout << maxa << endl;
            else
                cout << maxb << endl;
        }
        else {
    
    
            for (i = 1; i <= a / 2; i++) {
    
    
                memset(num, 0, sizeof(num));
                j = a - i;
                c[0] = i;
                c[1] = j;
                c[2] = b;
                c[3] = abs(i - j);
                c[4] = abs(i - b);
                c[5] = abs(i + j);
                c[6] = abs(i + b);
                c[7] = abs(j + b);
                c[8] = abs(j - b);
                c[9] = abs(i + j + b);
                c[10] = abs(i + j - b);
                c[11] = abs(i - j + b);
                c[12] = abs(i - j - b);
                for (int k = 0; k < 13; k++) {
    
    
                    num[c[k]]++;
                }
                for (int k = 1; k <= 200; k++) {
    
    
                    if (num[k] > 0) numa++;
                }
                if (maxa < numa) maxa = numa;
                numa = 0;
            }
            cout << maxa << endl;
        }
    }
    return 0;
}

后来我自己用C语言又暴力了一遍_

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
    
    
    int i,j,k,x,y,t;
    int a[20],num[201];
    int num1 = 0, num2 = 0;
    int max1 = 0, max2 = 0;
    scanf("%d",&t);
    while (t--)
    {
    
    
        max1 = 0, max2 = 0,num1 = 0, num2 = 0;
        scanf("%d %d",&x,&y);
        for (i = 1; i < x / 2; i++)
        {
    
    
            memset(num, 0, sizeof(num));
            j = x - i;
            a[0] = i;
            a[1] = j;
            a[2] = y;
            a[3] = abs(i - j);
            a[4] = abs(i - y);
            a[5] = abs(i + j);
            a[6] = abs(i + y);
            a[7] = abs(j + y);
            a[8] = abs(j - y);
            a[9] = abs(i + j + y);
            a[10] = abs(i + j - y);
            a[11] = abs(i - j + y);
            a[12] = abs(i - j - y);
            for (k = 0; k < 13; k++)
                num[a[k]]++;
            for (k = 1; k <= 200; k++)
            {
    
    
                if (num[k] > 0) num1++;
            }
            if (max1 < num1) max1 = num1;
            num1 = 0;
        }
        for (i = 1; i <= x / 2; i++)
        {
    
    
            memset(num, 0, sizeof(num));
            j = x - i;
            a[0] = i;
            a[1] = j;
            a[2] = x;
            a[3] = abs(i - j);
            a[4] = abs(i - x);
            a[5] = abs(i + j);
            a[6] = abs(i + x);
            a[7] = abs(j + x);
            a[8] = abs(j - x);
            a[9] = abs(i + j + x);
            a[10] = abs(i + j - x);
            a[11] = abs(i - j + x);
            a[12] = abs(i - j - x);
            for (k = 0; k < 13; k++)
            {
    
    
                num[a[k]]++;
            }
            for (k = 1; k <= 200; k++)
            {
    
    
                if (num[k] > 0) num2++;
            }
            if (max2 < num2) max2 = num2;
            num2 = 0;
        }
        if (max1 > max2)
            printf("%d\n",max1);
        else
             printf("%d\n",max2);
    }
return 0;
}

D题
D - Density of Power Network ZOJ - 3708
The vast power system is the most complicated man-made system and the greatest engineering innovation in the 20th century. The following diagram shows a typical 14 bus power system. In real world, the power system may contains hundreds of buses and thousands of transmission lines.

扫描二维码关注公众号,回复: 12124300 查看本文章

Network topology analysis had long been a hot topic in the research of power system. And network density is one key index representing the robustness of power system. And you are asked to implement a procedure to calculate the network density of power system.

The network density is defined as the ratio(比值) between number of transmission lines and the number of buses. Please note that if two or more transmission lines connecting the same pair of buses, only one would be counted in the topology analysis.

Input
The first line contains a single integer T (T ≤ 1000), indicating there are T cases in total.

Each case begins with two integers N and M (2 ≤ N, M ≤ 500) in the first line, representing the number of buses and the number of transmission lines in the power system. Each Bus would be numbered from 1 to N.

The second line contains the list of start bus number of the transmission lines, separated by spaces.

The third line contains the list of corresponding end bus number of the transmission lines, separated by spaces. The end bus number of the transmission lines would not be the same as the start bus number.

Output
Output the network density of the power system in a single line, as defined in above. The answer should round to 3 digits after decimal point.

Sample Input
3
3 2
1 2
2 3
2 2
1 2
2 1
14 20
2 5 3 4 5 4 5 7 9 6 11 12 13 8 9 10 14 11 13 13
1 1 2 2 2 3 4 4 4 5 6 6 6 7 7 9 9 10 12 14
Sample Output
0.667
0.500
1.429
题目大意:每个城市的公交系统都对应有传输路线和总路线,题目让你计算网络密度,一开始不知道网络密度是啥,看了大半天,最后才发现题目中已经给了计算方法【笑哭】,还是要多熟悉读英语题目啊!网络密度是传输线路比上总线路的值(保留三位小数),而且要查重。
C++代码(比赛时AC,当时我也想到用二维数组来解题,奈何太年轻没有快过孔老师,我和孔老师大体思路是一样的)

#include <bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
int main() {
    
    
    //ios::sync_with_stdio(false);
    //cin.tie();
    //cout.tie();
    int t;
    int n,m;
    double count1=0;
    int a[510][510];
    int x[510],y[510];
    cin >> t;
    while(t--)
    {
    
    
        count1=0;
        double cnt;
        memset(a,INF,sizeof(a));
       cin >> n >> m;
       for(int i=0;i<m;i++)
       cin >> x[i];
       for(int i=0;i<m;i++)
       cin >> y[i];
       for(int i=0;i<m;i++)
       {
    
    
           if(a[y[i]][x[i]] != 1)
           a[x[i]][y[i]]=1;
       }
       for(int i=1;i<=n;i++)
       {
    
    
           for(int j=1;j<=n;j++)
           {
    
    
               if(a[i][j]==1)count1++;
           }
       }
        cnt = count1/n*1.0;
        printf("%.3f\n",cnt);
    }
    return 0;
}

赛后总结反思

1、一定要重英语读题能力,多找一些题来读,争取提高自己的读题速度和寻找关键词的精度。
2、多学C++,C++相对于C语言来说更加便捷
3、多刷题,多思考,多总结做题思路

猜你喜欢

转载自blog.csdn.net/rookie636/article/details/107644072