zoukankan      html  css  js  c++  java
  • 第七届福建省赛

    Problem C
    Problem 2264 Card Game (First Edition)

    Accept: 16    Submit: 42
    Time Limit: 1000 mSec    Memory Limit : 32768 KB

     Problem Description

    Fat brother and Maze are playing a kind of special (hentai) game with some cards. There are N*2 cards in this game for the players to use, this is the card deck. The game goes for N rounds and in each round, Fat Brother would draw one card from the remaining card deck randomly and then Maze would draw one card from the remaining card deck randomly. Then they compare for the integers which is written on these two cards. The player with the higher number wins this round and score 1 victory point. And then these two cards are removed from the game such that they would not appear in the later rounds. As we all know, Fat Brother is very clever, so he would like to know the expect number of the victory points he could get if he knows all the integers written in these cards.

    Note that the integers written on these N*2 cards are pair wise distinct. At the beginning of this game, each player has 0 victory point.

     Input

    The first line of the data is an integer T (1 <= T <= 100), which is the number of the text cases.

    Then T cases follow, each case contains an integer N (1 <= N<=10000) which described before. Then follow one line with N*2 integers, which indicate the integers in these cards.

    All the integers are positive and no morethan 10000000.

     Output

    For each case, output the case number first, and then output the expect number of the victory points Fat Brother could get in this game. The answer should be rounded to 2 digits after the decimal point.

     Sample Input

    2
    1
    1 2
    2
    1 2 3 4

     Sample Output

    Case 1: 0.50
    Case 2: 1.00

     Source

    第七届福建省大学生程序设计竞赛-重现赛(感谢承办方闽江学院)

     这个题我也是醉了,各种方法难逃RE,wa。。。不过让我复习了组合数组的知识,真是不太好想啊

    现在我在意淫大佬做的答案时间那么短的是用了异或操做,但是异或并不知道这个数出现了几次,和几个数重复了啊

    二分的代码附上

    #include <stdio.h>
    #include <algorithm>
    using namespace std;
    int a[20005];
    int main(){
    int t,k=1;
    scanf("%d",&t);
    while(t--){
       int n;
       scanf("%d",&n);
       n*=2;
       for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
       }
      sort(a,a+n);
       int cnt=0;
       for(int i=0;i<n;i++){
       int pos=lower_bound(a,a+n,a[i])-a;
       cnt+=pos;
       }
       printf("Case %d: %.2f
    ",k++,cnt*0.5/(n-1));
    }
    return 0;}

    想了想直接sort去重也行啊,我的那个去重笨了点

    利用显而易见的cnt/4啊

    #include <stdio.h>
    #include <algorithm>
    using namespace std;
    int a[20005];
    int main(){
    int t,k=1;scanf("%d",&t);
    while(t--){
       int n;scanf("%d",&n);
       n*=2;
       for(int i=0;i<n;i++)scanf("%d",&a[i]);
       sort(a,a+n);
       int cnt=1;
       for(int i=1;i<n;i++)if(a[i]!=a[i-1])cnt++;
       printf("Case %d: %.2f
    ",k++,cnt/4.0);
    }
    return 0;}

    我特么就是个煞笔,这个题就是个n/2的问题啊,以为他说了wise distinct啊

    #include<stdio.h>
    int main(){
    int t,k=1,p;scanf("%d",&t);
    while(t--){
       int n;scanf("%d",&n);
       for(int i=0;i<2*n;i++){int p;scanf("%d",&p);}
       printf("Case %d: %.2f
    ",k++,n/2.0);
    }
    return 0;}
    Problem D
    Problem 2265 Card Game (Second Edition)

    Accept: 25    Submit: 63
    Time Limit: 1000 mSec    Memory Limit : 32768 KB

     Problem Description

    Fat brother and Maze are playing a kind of special (hentai) game with some cards. In this game, every player gets N cards at first and these are their own card deck. The game goes for N rounds and in each round, Fat Brother and Maze would draw one card from their own remaining card deck randomly and compare for the integer which is written on the cards. The player with the higher number wins this round and score 1 victory point. And then these two cards are removed from the game such that they would not appear in the later rounds. As we all know, Fat Brother is very clever, so he would like to know the expect number of the victory points he could get if he knows all the integers written in these cards.

    Note that the integers written on these N*2 cards are pair wise distinct. At the beginning of this game, each player has 0 victory point.

     Input

    The first line of the data is an integer T (1 <= T <= 100), which is the number of the text cases.

    Then T cases follow, each case contains an integer N (1 <=N<=10000) which described before. Then follow two lines with N integers each. The first N integers indicate Fat Brother’s cards and the second N integers indicate Maze’s cards.

    All the integers are positive and no more than 10000000.

     Output

    For each case, output the case number first, and then output the expect number of victory points Fat Brother would gets in this game. The answer should be rounded to 2 digits after the decimal point.

     Sample Input

    2
    1
    1
    2
    2
    1 3
    2 4

     Sample Output

    Case 1: 0.00 Case 2: 0.50

     Source

    第七届福建省大学生程序设计竞赛-重现赛(感谢承办方闽江学院)
    刚才又理解错了,不复习下概率的基本知识不行啊
    #include <stdio.h>
    #include <algorithm>
    using namespace std;
    int a[10002],b[10002];
    int main(){
    int t,k=1;
    scanf("%d",&t);
    while(t--){
       int n;
       scanf("%d",&n);
       for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
       }
       for(int i=0;i<n;i++){
        scanf("%d",&b[i]);
       }
       sort(b,b+n);
       int cnt=0;
       for(int i=0;i<n;i++){
       int pos=lower_bound(b,b+n,a[i])-b;
       cnt+=pos;
       }
       printf("Case %d: %.2f
    ",k++,cnt*1.0/n);
    }
    return 0;}
     Problem 2266 Card Game (Third Edition)

    Accept: 11    Submit: 15
    Time Limit: 1000 mSec    Memory Limit : 32768 KB

     Problem Description

    Fat brother and Maze are playing a kind of special (hentai) game with some cards. In this game, every player gets N cards at first and these are their own card decks. Each of these two decks of cards is stacking together at the beginning of the game, and their order would not change during this game. The game goes for N rounds and in each round, Fat Brother and Maze would draw one card from the top of their own remaining card deck and sum these two integers together. If this number is greater than 10, Fat Brother would score 1 victory point and otherwise Maze would score 1 victory points. And then these two cards are removed from the game such that they would not appear in the later rounds. As we all know, Fat Brother is very clever, so he would like to know the number of the victory points he could get if he knows all the integers written in these cards. At the beginning of this game, each player has 0 victory point.

     Input

    The first line of the date is an integer T (1 <= T <= 100), which is the number of the text cases.

    Then T cases follow, each case contains an integer N (1 <= N <= 10000) which described before. Then follow two lines with N integers each. The first N integers indicate the cards which Fat Brother gets from top to bottom, and the second N integers indicate the cards which Maze gets from top to bottom.

    All the integers are positive and least than 10.

     Output

    For each case, output the case number first, and then output the number of victory points Fat Brother would gets in this game.

     Sample Input

    2
    1
    5
    6
    2
    3 4
    3 4

     Sample Output

    Case 1: 1
    Case 2: 0

     Source

    第七届福建省大学生程序设计竞赛-重现赛(感谢承办方闽江学院)
    #include <stdio.h>
    #include <string.h>
    const int  N=20200;
    int a[N],b[N];
    int main() {
        int t,n,q=1;
        scanf("%d",&t);
        while(t--) {
            memset(a,0,sizeof(a));
            memset(b,0,sizeof(b));
            scanf("%d",&n);
            for(int i=0; i<n; i++)
                scanf("%d",&a[i]);
            for(int i=0; i<n; i++)
                scanf("%d",&b[i]);
            int sum=0;
            for(int i=0; i<n; i++)
                if(a[i]+b[i]>10)
                    sum++;
            printf("Case %d: %d
    ",q++,sum);
    
        }
        return 0;
    }

     Problem G

    Problem 2268 Cutting Game

    Accept: 15    Submit: 24
    Time Limit: 1000 mSec    Memory Limit : 32768 KB

     Problem Description

    Fat brother and Maze are playing a kind of special (hentai) game with a piece of gold of length N where N is an integer. Although, Fat Brother and Maze can buy almost everything in this world (except love) with this gold, but they still think that is not convenient enough. Just like if they would like to buy the moon with M lengths of the gold, the man who sold the moon need to pay back Fat Brother and Maze N-M lengths of the gold, they hope that they could buy everything they can afford without any change. So they decide to cut this gold into pieces. Now Fat Brother and Maze would like to know the number of the pieces they need to cut in order to make them fulfill the requirement. The number of the gold pieces should be as small as possible. The length of each piece of the gold should be an integer after cutting.

     Input

    The first line of the data is an integer T (1 <= T <= 100), which is the number of the text cases.

    Then T cases follow, each case contains an integer N (1 <= N <= 10^9) indicated the length of the gold.

     Output

    For each case, output the case number first, and then output the number of the gold pieces they need to cut.

     Sample Input

    1 3

     Sample Output

    Case 1: 2

     Hint

    In the first case, the gold can be cut into 2 pieces with length 1 and 2 in order to buy everything they can afford without change.

     Source

    第七届福建省大学生程序设计竞赛-重现赛(感谢承办方闽江学院)
    就是给你一块重n的金块,你能给他凑成1~n,本来我想这要用天平思想
    这个问题是这样出现过的:
    我们都知道人民币的面值是1、2、5、10,为什么是这个数值呢,我们分析了下发现,从1−10的每个数字都可以由每种面值选出至多一张通过加法和减法(找钱)来构成,(比如:1+2=3,5−1=4,5+1=6,5+2=7,1+2+5=8,10−1=9)
    但是实际上,我们只需要1、2、7三种面值就可以组成1−10的每一个数字了
    (1+2=3,7−1−2=4,7−2=5,7−1=6,7+1=8,7+2=9,7+1+2=10)
    那么现在问题来了,给一个数n,请问最少需要多少种不同的面值就可以构成从1−n的所有数字,注意在构成每一个数字时同种面值不能超过1张。
    用3^k (k=0,1,2,3,)可以表示出1到(3^(k+1)-1)/2中的所有数
    n<=(3^(k+1)-1)/2
    2n+1<=3^(k+1)
    k+1>=lg(2n+1)/lg(3)
    k+1的最小值就是我们要的结果
    你说的这个模型与天平称1-n整数重量的物体所要用的砝码序列是一样的,砝码在这里可以放到任一托盘
    1,3,9,27,81,243,。。。
    (int)ceil((log10((2*n+1)*1.0))/(log10(3.0)))

    好啦,回到这道题,他要满足的要求没有上面那么苛刻,想二进制里,好像就能实现题目所述的操作,就是统计二进制位数而已嘛

    #include <stdio.h>
    int main(){
    int t,k=1;
    scanf("%d",&t);
    while(t--){
        int n;
        scanf("%d",&n);
        for(int i=1;i<31;i++){
            if(1<<i>=n){
                printf("Case %d: %d
    ",k++,i);
            break;}
        }
    }
    return 0;}
     Problem J X

    Time Limit: 1500 mSec    Memory Limit : 32768 KB

     Problem Description

    X is a fully prosperous country, especially known for its complicated transportation networks. But recently, for the sake of better controlling by the government, the president Fat Brother thinks it’s time to close some roads in order to make the transportation system more effective.

    Country X has N cities, the cities are connected by some undirected roads and it’s possible to travel from one city to any other city by these roads. Now the president Fat Brother wants to know that how many roads can be closed at most such that the distance between any two cities in country X does not change. Note that the distance between city A and city B is the minimum total length of the roads you need to travel from A to B.

     Input

    The first line of the date is an integer T (1 <= T <= 50), which is the number of the text cases.

    Then T cases follow, each case starts with two numbers N, M (1 <= N <= 100, 1 <= M <= 40000) which describe the number of the cities and the number of the roads in country X. Each case goes with M lines, each line consists of three integers x, y, s (1 <= x, y <= N, 1 <= s <= 10, x is not equal to y), which means that there is a road between city x and city y and the length of it is s. Note that there may be more than one roads between two cities.

     Output

    For each case, output the case number first, then output the number of the roads that could be closed. This number should be as large as possible.

    See the sample input and output for more details.

     Sample Input

    2
    2 3
    1 2 1
    1 2 1
    1 2 2
    3 3
    1 2 1
    2 3 1
    1 3 1

     Sample Output

    Case 1: 2
    Case 2: 0

     Source

    第七届福建省大学生程序设计竞赛-重现赛(感谢承办方闽江学院)
    因为数据量只有100,并不大,Floyd跑一遍,在考虑去边的问题
    1两点间的最短路小雨两点间的实际相连边,则相连边可以删除。
    2两点间的最短路是实际相连边,并且有一个点k使得ij==ik+kj。则ij这条边可以删除。 

     本来以为是个什么神奇操作呢,看了别人代码材质这种骚操作

    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    const int inf=0x3f3f3f3f;
    const int N=105;
    int a[N][N],ma[N][N],vis[N][N];
    int n,m;
    void Floyd() {
        for(int k=1; k<=n; ++k)
            for(int i=1; i<=n; ++i)
                for(int j=1; j<=n; ++j) {
                    if(i==j)
                        continue;
                    if(a[i][k]<inf&&a[k][j]<inf&&a[i][j]>=a[i][k]+a[k][j])
                        a[i][j]=a[i][k]+a[k][j],vis[i][j]=1;
                }
    }
    int main() {
        int t,res=1;
        scanf("%d",&t);
        while(t--) {
            memset(vis,0,sizeof(vis));
            memset(a,inf,sizeof(a));
            scanf("%d%d",&n,&m);
            int u,v,w,ans=0;
            for(int i=1; i<=m; ++i) {
                scanf("%d%d%d",&u,&v,&w);
                if(a[u][v]<inf)
                    ++ans;
                a[u][v]=a[v][u]=min(w,a[u][v]);
            }
            memcpy(ma,a,sizeof(ma));
            Floyd();
            for(int i=1; i<=n; ++i)
                for(int j=1; j<i; ++j) {
                    if(ma[i][j]==inf)
                        continue;
                    if((a[i][j]<=ma[i][j]&&vis[i][j]))
                        ++ans;
                }
            printf("Case %d: %d
    ",res++,ans);
        }
        return 0;
    }
    大佬您太强了,还请多多指教哎
  • 相关阅读:
    生成器
    字典生成式
    列表推导式
    函数基础实战之ATM和购物车系统
    函数基础小结
    函数嵌套
    可变长参数
    函数参数
    java NIO(三)----通道(Channel)
    java NIO(二)----直接缓冲区和非直接缓冲区
  • 原文地址:https://www.cnblogs.com/BobHuang/p/7204340.html
Copyright © 2011-2022 走看看