zoukankan      html  css  js  c++  java
  • 湖南大学第十五届程序设计竞赛(重现赛)

    I Algorithm Choosing Mushrooms

    时间限制:C/C++ 1秒,其他语言2秒
    空间限制:C/C++ 32768K,其他语言65536K
    64bit IO Format: %lld

    题目描述

    Baby bear and his good friends are very fond of mushrooms. On this day, they go to 402 mushroom field together. Kuangyeye, the owner of the mushroom field, is very happy to see the children. He is going to give the children some mushrooms, so he takes them to a warehouse.

    In the warehouse, there are N baskets in a row, numbered from 1 to N, with some mushrooms in each basket. Baby bear and his friends can take several baskets of mushrooms, but Kuangyeye has several requirements:

    ·Kuangyeye likes to be neat and tidy. He asks the children to take away only the consecutively numbered baskets when they take the mushrooms. This means that if the children choose the 4th, 5th and 6th baskets of mushrooms, they can't choose the 9th basket unless they also choose the 7th and 8th baskets.

    ·Kuangyeye likes all of them, so he asks each child to get the same number of mushrooms. This means that the total number of mushrooms the children take away must be P = k * M, where k is an integer and M is the total number of children.

    ·Kuangyeye made a record of the number of mushrooms in each basket. He asks the children not to put some mushrooms in other baskets or throw them away. This means that when the children take a basket of mushrooms, they must take away all the mushrooms in the basket.

    Now given the number of mushrooms in a row of N baskets, please answer:

    1. The maximum number of mushrooms that baby bear and his friends can take away.

    2. The maximum number of baskets that baby bear and his friends can take away.

    Please note that the answers to questions 1 and 2 May not come from the same situation!!!

    输入描述:

    The input contains a single sample.

    The first line of input has two integers N and M (1 <= N,M <= 200000) separated by space, representing the number of baskets and the number of children.

    The second line of input has N integer A1,A2,……,AN (1 <= A1,A2,……,AN <= 1e9)separated by space, representing the number of mushrooms in the basket numbered from 1 to N.

    输出描述:

    Output two Numbers separated by space. The maximum number of mushrooms they could get and the maximum number of baskets they could take. If they can’t meet Kuangyeye's demands, please output “0 0”.
    示例1

    输入

    复制
    8 7
    2 1 15 5 8 9 1 7000

    输出

    复制
    7000 3

    说明

    Choose basket 8 to get the most mushrooms, but choose basket 2, 3, 4 (or 3, 4, 5) to get the most baskets.
    示例2

    输入

    复制
    7 13
    7 1000 1000 1000 1000 1000 6

    输出

    复制
    0 0

    说明

    It's impossible to meet Kuangyeye's demands.
     
    这题并没有做出来orz
     1 //江寒月熙丶 提交的代码https://ac.nowcoder.com/acm/contest/view-submission?submissionId=40729426
     2 
     3 #include <bits/stdc++.h>
     4 #define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
     5 #define IT set<node>::iterator
     6 #define mem(a) memset(a,0,sizeof(a))
     7 using namespace std;
     8 typedef long long LL;
     9 typedef long long ll;
    10 const int maxn=1e6+5;
    11 ll a[maxn];
    12 ll start[maxn];
    13 ll sumzz[maxn];
    14 unordered_map<int,int>mp;
    15 int main()
    16 {
    17     #ifdef ONLINE_JUDGE
    18     FAST_IO;
    19     #endif // ONLINE_JUDGE
    20    int n,k;
    21    cin>>n>>k;
    22    for(int i=1;i<=n;i++)
    23         cin>>a[i],sumzz[i]=sumzz[i-1]+a[i];
    24    ll sum=0;
    25    ll ans=0;
    26    ll maxz=0;
    27    for(int i=1;i<=n;i++)
    28    {
    29        sum=(sum+a[i])%k;
    30        if(sum!=0&&start[sum]==0)
    31             start[sum]=i;
    32        else {
    33         ans=max(ans,i-start[sum]);
    34         maxz=max(maxz,sumzz[i]-sumzz[start[sum]]);
    35        }
    36    }
    37    cout<<maxz<<' '<<ans<<endl;
    38 }
    江寒月熙丶 提交的代码
    学习一下大佬的代码orz第一次知道了unordered_map,所以想在新get 的知识点中补充一下!
     
     
    C One Piece
    时间限制:C/C++ 1秒,其他语言2秒
    空间限制:C/C++ 32768K,其他语言65536K
    64bit IO Format: %lld

    题目描述

    Luffy once saw a particularly delicious food, but he didn't have the money, so he asked Nami for money. But we all know that Nami can't easily give money to Luffy. Therefore, Nami decided to take a test of Luffy. If Luffy was right, Nami would give him money, otherwise Luffy would only be hungry. The problem is as follows: Give you an 32-bit integer n and find the number of 1 in the binary representation of the integer.
    You are the most trusted friend of Luffy, and he is now asking for help.

    输入描述:

    There are multiple test cases. The first line of the input contains an integer T(T<=10), indicating the number of test cases. For each test case:

    The first line contains an 32-bit integer n(-1e9 <= n <= 1e9)

    输出描述:

    For each test case output one line containing one integer, indicating the number of  1 in the binary representation of the integer.
    示例1

    输入

    复制
    3
    1
    2
    3

    输出

    复制
    1
    1
    2

    说明

    The binary of 1 is 01, so the number of 1 is 1, and the binary of  2 is 10, so the number of 1 is 1,The binary of 3 is 11, so the number of 1 is 2.
    示例2

    输入

    复制
    1
    -1

    输出

    复制
    32

    说明

    The binary of -1 is 11111111111111111111111111111111, so the number of 1 is 32.
     
     1  
     2 void Binarycout(int n) 
     3 { 
     4     int cnt;
     5     for (int i=31;i>=0;i--) 
     6     { 
     7      if(((n>>i)&1)==1)
     8         cnt++; 
     9     } 
    10     cout<<cnt<<endl; 
    11 }
    12  
    13 int main()
    14 {
    15     long long t,n;
    16     scanf("%lld",&t);
    17     while(t--)
    18     {
    19         scanf("%lld",&n);Binarycout(n);
    20     }
    21      
    22     return 0;
    23 }
    我的C题5ms
     褪色的夜提交的代码 2ms
     1 int main()
     2 {
     3      
     4     int t;scanf("%d",&t);
     5     while(t--)
     6     {
     7         int value = 0;
     8         int count = 0;
     9         scanf("%d",&value);
    10         while(value != 0)
    11         {  
    12             count++;
    13             value = (value & (value-1));
    14         }
    15         printf("%d
    ",count);
    16     }
    17     return 0;
    18 }
    学长聚聚的代码

    F  Cards with Numbers

    时间限制:C/C++ 1秒,其他语言2秒
    空间限制:C/C++ 262144K,其他语言524288K
    64bit IO Format: %lld

    题目描述

    AFei has many cards. Each card has a number written on it. Now he wants to takes some out of his card and puts them in a box. And he wants to know whether the card with the number x was in the box. So he has the following two operations:
    • 0 x (It means to put a card with the number x in the box.)
    • 1 x   (It means to query if there is a card with the number x in the box.)

    输入描述:

    The first line of the input is an integer n (1 <= n <= 10
    6
    ), the number of operations. Next n lines  represent n operations, and two integers k ( k∈{0,1}) and x (0<=x<=10
    9
    )  are separated by spaces on each line, as described above.

    输出描述:

    For each query, output one line "yes" if there is a card with the number x in the box, otherwise output one line "no".
    示例1

    输入

    复制
    5
    0 1
    1 2
    0 2
    1 3
    1 2

    输出

    复制
    no
    no
    yes
     题解:这题历经曲折。首先一开始使用桶放置。结果不管是int还是bool数组,它都mle(最早段错误是因为少打了一个0,但是之前有所察觉加了0,但是mle没太在意),然后改成map tle。。最后是vector +bool AC了。
     1 int main()
     2 {
     3     //memset(a,false,sizeof(a));
     4     int x;
     5     int t;
     6     scanf("%d",&t);
     7     vector<bool > v(1e9);
     8     int q;
     9     while(t--)
    10     {
    11         scanf("%d%d",&q,&x);
    12         if(q==0)
    13             v[x]=true;
    14         if(q==1)
    15         {
    16             if(v[x]==true)
    17                 printf("yes
    ");
    18             else
    19                 printf("no
    ");
    20         }
    21     }
    22 }
    F

    看了其他大佬的代码,其实可以取模处理,不过~~有点麻烦嘤嘤嘤

     1 /*Jadlokin_Scarlet 提交的代码https://ac.nowcoder.com/acm/contest/view-submission?submissionId=40728436*/
     2 
     3 
     4 int n,f,x;
     5 unordered_set<int> s;
     6 int main() {
     7     scanf("%d",&n);
     8     while(n--){
     9         scanf("%d %d",&f,&x);
    10         if(f == 0){
    11             s.insert(x);
    12         }else {
    13             printf(s.count(x) == 1?"yes
    ":"no
    ");
    14         }
    15     }
    16     return 0;
    17 }
    Jadlokin_Scarlet 提交的代码

    unordered set。。原来unordered STL的应用如此广泛QWQ|||这也是代码简短的submission的主流做法

     1 const int maxn=1000000100;
     2 int n,c,x;
     3 bitset<maxn> vis;
     4 int main()
     5 {
     6     cin>>n;
     7     while(n--)
     8     {
     9         scanf("%d%d",&c,&x);
    10         c?printf(vis[x]?"yes
    ":"no
    "):vis[x]=1;
    11     }
    12     return 0;
    13 }
    hnust_liuzelin 提交的代码

    这个感觉更厉害的样子orz   bitset

    链接:https://ac.nowcoder.com/acm/contest/908/G
    来源:牛客网

    G Longest Palindrome Substring

    时间限制:C/C++ 1秒,其他语言2秒
    空间限制:C/C++ 32768K,其他语言65536K
    64bit IO Format: %lld

    题目描述

        A palindrome is a symmetrical string, that

    is, a string read identically from left to right as well as from right to left. For example, ”a”、”aba”、“abba” are palindrome and “abc”、”aabb” are not.

        Let’s define a new function f(s).

        For some string s, f(s) is the length of the longest palindrome substring.

        Now you should decide for the given string s, whether f(s) is great than 1.
        The string s only contains lowercase letters.
     

    输入描述:

    The first line of the input contains one integer n ------ the length of the string (1<=n<=10^5)

    The second line of the input is the string.

    输出描述:

    If f(s) great than 1, print “YES” without quote

    Else print “NO” without quote
    示例1

    输入

    复制
    4
    abcd

    输出

    复制
    NO
    示例2

    输入

    复制
    4
    abcb

    输出

    复制
    YES
    ..
     1 #include <stdio.h>
     2 int main()
     3 {
     4     int n,i,flag=0;
     5     char s[100000];
     6     scanf("%d",&n);
     7     getchar();
     8     gets(s);
     9     for(i=0;i<n;i++){
    10         if(s[i]==s[i+1]||s[i]==s[i+2])
    11         {
    12             flag=1;
    13             break;
    14         }
    15     }
    16     if(flag==1){
    17         printf("YES
    ");
    18     }
    19     else{
    20         printf("NO
    ");
    21     }
    22  }
    G
    ..
     
     
  • 相关阅读:
    父页面与子页面间相互传值
    PS常用技能综合
    JS 提交form表单
    html实体字符
    js基础
    Delegate模式
    IOS-基础知识
    测试工具综合
    [Linux] Nginx 提供静态内容和优化积压队列
    [Linux] Nginx响应压缩gzip
  • 原文地址:https://www.cnblogs.com/greenaway07/p/10960667.html
Copyright © 2011-2022 走看看