zoukankan      html  css  js  c++  java
  • HDU 5922 Minimum’s Revenge 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)

    Minimum’s Revenge

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 283    Accepted Submission(s): 219


    Problem Description
    There is a graph of n vertices which are indexed from 1 to n. For any pair of different vertices, the weight of the edge between them is the least common multipleof their indexes.

    Mr. Frog is wondering about the total weight of the minimum spanning tree. Can you help him?
     
    Input
    The first line contains only one integer T (T100), which indicates the number of test cases.

    For each test case, the first line contains only one integer n (2n109), indicating the number of vertices.
     
    Output
    For each test case, output one line "Case #x:y",where x is the case number (starting from 1) and y is the total weight of the minimum spanning tree.
     
    Sample Input
    2 2 3
     
    Sample Output
    Case #1: 2 Case #2: 5
    Hint
    In the second sample, the graph contains 3 edges which are (1, 2, 2), (1, 3, 3) and (2, 3, 6). Thus the answer is 5.
     
    Source
     
    Recommend
    wange2014   |   We have carefully selected several similar problems for you:  5932 5931 5930 5929 5928 
     
    Statistic | Submit | Discuss | Note

    题目链接:

      http://acm.hdu.edu.cn/showproblem.php?pid=5922

    题目大意:

      N个点1~N(N<=109),x与y之间的边的权为x与y的最小公倍数,求最小生成树的边权和。

    题目思路:

      【模拟】【构造】

      这样构造数:质数与1相连,其余与任意一个因子相连,这样边权最小,所以当N=2时答案为2,否则为2+3+...+N。

     1 //
     2 //by coolxxx
     3 //#include<bits/stdc++.h>
     4 #include<iostream>
     5 #include<algorithm>
     6 #include<string>
     7 #include<iomanip>
     8 #include<map>
     9 #include<stack>
    10 #include<queue>
    11 #include<set>
    12 #include<bitset>
    13 #include<memory.h>
    14 #include<time.h>
    15 #include<stdio.h>
    16 #include<stdlib.h>
    17 #include<string.h>
    18 //#include<stdbool.h>
    19 #include<math.h>
    20 #pragma comment(linker,"/STACK:1024000000,1024000000")
    21 #define min(a,b) ((a)<(b)?(a):(b))
    22 #define max(a,b) ((a)>(b)?(a):(b))
    23 #define abs(a) ((a)>0?(a):(-(a)))
    24 #define lowbit(a) (a&(-a))
    25 #define sqr(a) ((a)*(a))
    26 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
    27 #define mem(a,b) memset(a,b,sizeof(a))
    28 #define eps (1e-10)
    29 #define J 10000
    30 #define mod 1000000007
    31 #define MAX 0x7f7f7f7f
    32 #define PI 3.14159265358979323
    33 #define N 100004
    34 using namespace std;
    35 typedef long long LL;
    36 double anss;
    37 LL aans;
    38 int cas,cass;
    39 LL n,m,lll,ans;
    40 
    41 int main()
    42 {
    43     #ifndef ONLINE_JUDGEW
    44 //    freopen("1.txt","r",stdin);
    45 //    freopen("2.txt","w",stdout);
    46     #endif
    47     int i,j,k;
    48     int x,y,z;
    49 //    init();
    50 //    for(scanf("%d",&cass);cass;cass--)
    51     for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
    52 //    while(~scanf("%s",s))
    53 //    while(~scanf("%d%d",&n,&m))
    54     {
    55         printf("Case #%d: ",cass);
    56         scanf("%lld",&n);
    57         if(n==2)puts("2");
    58         else printf("%lld
    ",n*(n+1)/2-1);
    59     }
    60     return 0;
    61 }
    62 /*
    63 //
    64 
    65 //
    66 */
    View Code

    Minimum’s Revenge

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 283    Accepted Submission(s): 219


    Problem Description
    There is a graph of n vertices which are indexed from 1 to n. For any pair of different vertices, the weight of the edge between them is the least common multipleof their indexes.

    Mr. Frog is wondering about the total weight of the minimum spanning tree. Can you help him?
     
    Input
    The first line contains only one integer T (T100), which indicates the number of test cases.

    For each test case, the first line contains only one integer n (2n109), indicating the number of vertices.
     
    Output
    For each test case, output one line "Case #x:y",where x is the case number (starting from 1) and y is the total weight of the minimum spanning tree.
     
    Sample Input
    2 2 3
     
    Sample Output
    Case #1: 2 Case #2: 5
    Hint
    In the second sample, the graph contains 3 edges which are (1, 2, 2), (1, 3, 3) and (2, 3, 6). Thus the answer is 5.
     
    Source
     
    Recommend
    wange2014   |   We have carefully selected several similar problems for you:  5932 5931 5930 5929 5928 
     
    Statistic | Submit | Discuss | Note
  • 相关阅读:
    Object detection overview
    CMU: A Baseline for 3D Multi-Object Tracking
    A Review of Visual Trackers and Analysis of its Application to Mobile Robot
    js回顾学习笔记
    写给.NET开发者的Python教程(二):基本类型和变量
    钽电容 Case B 和 MLCC 1210 区别
    linux sed命令就是这么简单
    shell 字符串处理汇总(查找,替换等等)
    linux shell 字符串操作详解 (长度,读取,替换,截取,连接,对比,删除,位置 )
    php 给定时间戳 加一月 如果下一月天数不够就返回下一月最后一天
  • 原文地址:https://www.cnblogs.com/Coolxxx/p/5982193.html
Copyright © 2011-2022 走看看