• 寒假积分赛(二)


    A - Jolly Jumpers

    A sequence of n > 0 integers is called a jolly jumper if the absolute values of the difference between successive elements take on all the values 1 through n-1. For instance,

    1 4 2 3

    is a jolly jumper, because the absolutes differences are 3, 2, and 1 respectively. The definition implies that any sequence of a single integer is a jolly jumper. You are to write a program to determine whether or not each of a number of sequences is a jolly jumper.


    Input

    Each line of input contains an integer n < 3000 followed by n integers representing the sequence.


    Output

    For each line of input, generate a line of output saying "Jolly" or "Not jolly".

    Sample Input

    4 1 4 2 3
    5 1 4 2 -1 6
    Sample Output
    Jolly
    Not jolly

    题意:求两个数之间的差距是否都在1~n-1之间且没有重复的

    思路:差分+排序
     1 #include <bits/stdc++.h>
     2 #define  int long long
     3 #define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
     4 const int maxn=1e5+50;
     5 const int INF=0x3f3f3f3f;
     6 using namespace std;
     7 int a[maxn];
     8 int b[maxn];
     9 signed main(){
    10       IOS;
    11    int n;
    12    while(cin>>n){
    13        for(int i=0;i<n;i++)cin>>a[i];
    14        b[0]=0;
    15        int flag=0;
    16        for(int i=1;i<n;i++){
    17            b[i]=abs(a[i]-a[i-1]);
    18        }
    19     for(int i=0;i<n;i++){
    20            if(b[i]>=n)flag=1;
    21        }
    22        sort(b+1,b+n);
    23      for(int i=1;i<n;i++){
    24          if(b[i]!=i)flag=1;
    25      }
    26     if(flag==1)cout<<"Not jolly"<<'
    ';
    27     else cout<<"Jolly"<<'
    ';
    28    }
    29   
    30  return 0;
    31 }

    B - 验证角谷猜想、

    数论中有许多猜想尚未解决,其中有一个被称为“角谷猜想”的问题,该问题在五、六十年代的美国多个著名高校中曾风行一时,这个问题是这样描述的:任何一个大于一的自然数,如果是奇数,则乘以三再加一;如果是偶数,则除以二;得出的结果继续按照前面的规则进行运算,最后必定得到一。现在请你编写一个程序验证他的正确性。

    Input本题有多个测试数据组,第一行为测试数据组数N,接着是N行的正整数。
    Output输出验证“角谷猜想”过程中的奇数,最后得到的1不用输出;每个测试题输出一行;每行中只有两个输出之间才能有一个空格;如果没有这样的输出,则输出:No number can be output !。
    Sample Input
    4
    5
    9
    16
    11
    Sample Output
    5
    9 7 11 17 13 5
    No number can be output !
    11 17 13 5
    思路:纯模拟水题(注意格式)
    #include <bits/stdc++.h>
    #define  int long long
    #define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
    const int maxn=2e5+50;
    const int INF=0x3f3f3f3f;
    using namespace std;
    signed main(){
          IOS;
          int n;cin>>n;
          while(n--){
          int m;cin>>m;
          int flag=0;
          int flag2=0;
          if(m&1){cout<<m;
          flag2=1;
          }
         while(m!=1){ 
         if(m&1){
         m=m*3+1;flag=1;
          }
          else m/=2;
          if(m&1&&m!=1){
              if(flag2==1)cout<<" "<<m;
              else {
                  cout<<m;flag2=1;
              }
          }
         }
          
          if(flag==0)cout<<"No number can be output !";cout<<'
    ';
        }
       
     return 0;
    }

    C - 取石子游戏

    有两堆石子,数量任意,可以不同。游戏开始由两个人轮流取石子。游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子;二是可以在两堆中同时取走相同数量的石子。最后把石子全部取完者为胜者。现在给出初始的两堆石子的数目,如果轮到你先取,假设双方都采取最好的策略,问最后你是胜者还是败者。

    Input输入包含若干行,表示若干种石子的初始情况,其中每一行包含两个非负整数a和b,表示两堆石子的数目,a和b都不大于1,000,000,000。Output输出对应也有若干行,每行包含一个数字1或0,如果最后你是胜者,则为1,反之,则为0。Sample Input
    2 1
    8 4
    4 7
    Sample Output
    0
    1
    0
    思路:威佐夫博弈套公式就好了
    #include <bits/stdc++.h>
    #define  int long long
    #define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
    const int maxn=2e5+50;
    const int INF=0x3f3f3f3f;
    using namespace std;
    signed main(){
      IOS;
      int a,b;
      while(cin>>a>>b){
            int a1=min(a,b);
          int b1=max(a,b);
          int t=b1-a1;
          int s=(int)((sqrt(5.0)+1)/2*t);
          if(s==a1)cout<<0<<'
    ';
          else cout<<1<<'
    ';
        }
     return 0;
    }

    D - 二分查找(二)

    蒜头君手上有个长度为 n 的数组 A。由于数组实在太大了,所以蒜头君也不知道数组里面有什么数字,所以蒜头君会经常询问在数组 A 中,大于等于 x

    的最小值是多大?

    输入格式

    第一行输入两个整数nm,分别表示数组的长度和查询的次数。

    接下来一行有 n整数 ai

    接下来 m行,每行有 1 个整数 x,表示蒜头君询问的整数。

    输出格式

    对于每次查询,如果可以找到,输出这个整数。

    否则输出 1

    数据范围

    1n,m105,0x106

    Sample Input
    10 5
    1 1 1 2 3 5 5 7 8 9
    0
    1
    4
    9
    10
    Sample Output
    1
    1
    5
    9
    -1

    思路:二分模板STL的lower_bound()直接用
    #include <bits/stdc++.h>
    #define  int long long
    #define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
    const int maxn=1e5+50;
    const int INF=0x3f3f3f3f;
    using namespace std;
    int a[maxn];
    
    signed main(){
          IOS;
          int n,m;
          cin>>n>>m;
          for(int i=1;i<=n;i++)cin>>a[i];
          sort(a+1,a+1+n);
          for(int i=1;i<=m;i++){
              int x;cin>>x;
              int l=1,r=n;
              if(x<a[1])cout<<a[1]<<'
    ';
              else if(x>a[n])cout<<-1<<'
    ';
              else { 
               int ans=lower_bound(a+1,a+n+1,x)-a;
               
            cout<<a[ans]<<'
    ';
           }
          }
     return 0;
    }

    E - 最短路

    
    
    在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt。但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店到赛场的路线,你可以帮助他们吗?

    
    
    
    

    Input输入包括多组数据。每组数据第一行是两个整数N、M(N<=100,M<=10000),N表示成都的大街上有几个路口,标号为1的路口是商店所在地,标号为N的路口是赛场所在地,M则表示在成都有几条路。N=M=0表示输入结束。接下来M行,每行包括3个整数A,B,C(1<=A,B<=N,1<=C<=1000),表示在路口A与路口B之间有一条路,我们的工作人员需要C分钟的时间走过这条路。
    输入保证至少存在1条商店到赛场的路线。
    Output对于每组输入,输出一行,表示工作人员从商店走到赛场的最短时间Sample Input
    2 1
    1 2 3
    3 3
    1 2 5
    2 3 5
    3 1 2
    0 0
    Sample Output
    3
    2
    Sponsor
    (比赛没写出来,留着学完floyd写

    F - 寒冰王座

    不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票(记住,只有一张钞票),为了防止自己在战斗中频繁的死掉,他决定给自己买一些道具,于是他来到了地精商店前.

    死亡骑士:"我要买道具!"

    地精商人:"我们这里有三种道具,血瓶150块一个,魔法药200块一个,无敌药水350块一个."

    死亡骑士:"好的,给我一个血瓶."

    说完他掏出那张N元的大钞递给地精商人.

    地精商人:"我忘了提醒你了,我们这里没有找客人钱的习惯的,多的钱我们都当小费收了的,嘿嘿."

    死亡骑士:"......"

    死亡骑士想,与其把钱当小费送个他还不如自己多买一点道具,反正以后都要买的,早点买了放在家里也好,但是要尽量少让他赚小费.

    现在死亡骑士希望你能帮他计算一下,最少他要给地精商人多少小费.

    Input输入数据的第一行是一个整数T(1<=T<=100),代表测试数据的数量.然后是T行测试数据,每个测试数据只包含一个正整数N(1<=N<=10000),N代表死亡骑士手中钞票的面值.

    注意:地精商店只有题中描述的三种道具.
    Output对于每组测试数据,请你输出死亡骑士最少要浪费多少钱给地精商人作为小费.
    Sample Input
    2
    900
    250
    Sample Output
    0
    50
    思路:这题很羞耻的WA了两发,然后才发现第三种不需要考虑,150和200那就直接大于300的%50就好了
    因为所有的剩余大于20的都可以把一个150的换成200的;
    #include <bits/stdc++.h>
    #define  int long long
    #define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
    const int maxn=2e5+50;
    const int INF=0x3f3f3f3f;
    using namespace std;
    signed main(){
      IOS;
      int t;cin>>t;
      while(t--) {
          int n;cin>>n;
          int ans;
          if(n<150)ans=n;
          else if(n>=150&&n<200)ans=n-150;
          else if(n>=200&&n<300)ans=n-200;
          else ans=n%50;
          cout<<ans<<'
    ';
    
          
    
      }
     return 0;
    }

    G - 诡异的楼梯

    H - Round and Round We Go

    留着补题

    I - 免费馅饼

    都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼。说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁的10米范围内。馅饼如果掉在了地上当然就不能吃了,所以gameboy马上卸下身上的背包去接。但由于小径两侧都不能站人,所以他只能在小径上接。由于gameboy平时老呆在房间里玩游戏,虽然在游戏中是个身手敏捷的高手,但在现实中运动神经特别迟钝,每秒种只有在移动不超过一米的范围内接住坠落的馅饼。现在给这条小径如图标上坐标:

    为了使问题简化,假设在接下来的一段时间里,馅饼都掉落在0-10这11个位置。开始时gameboy站在5这个位置,因此在第一秒,他只能接到4,5,6这三个位置中其中一个位置上的馅饼。问gameboy最多可能接到多少个馅饼?(假设他的背包可以容纳无穷多个馅饼)

    Input输入数据有多组。每组数据的第一行为以正整数n(0<n<100000),表示有n个馅饼掉在这条小径上。在结下来的n行中,每行有两个整数x,T(0<T<100000),表示在第T秒有一个馅饼掉在x点上。同一秒钟在同一点上可能掉下多个馅饼。n=0时输入结束。
    Output每一组输入数据对应一行输出。输出一个整数m,表示gameboy最多可能接到m个馅饼。
    提示:本题的输入数据量比较大,建议用scanf读入,用cin可能会超时。

    Sample Input
    6
    5 1
    4 1
    6 1
    7 2
    7 2
    8 3
    0
    Sample Output
    4
    思路:基础DP直接倒推就欧克啦
    边界记得特殊处理一下就好了
    #include <bits/stdc++.h>
    //#define  int long long
    #define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
    const int maxn=1e5+50;
    const int INF=0x3f3f3f3f;
    using namespace std;
    int dp[11][maxn];
    signed main(){
      IOS;
      int n;
      while(cin>>n) {
          if(n==0)break;
          int t=0;
          memset(dp,0,sizeof(dp));
          for(int i=0;i<n;i++){
              int x,t1;cin>>x>>t1;
              dp[x][t1]++;
              t=max(t,t1);
          }    
         
        for(int i=t-1;i>=0;i--){
            dp[0][i]+=max(dp[0][i+1],dp[1][i+1]);
            dp[10][i]+=max(dp[10][i+1],dp[9][i+1]);
           for(int j=1;j<10;j++){
               dp[j][i]+=max(dp[j][i+1],max(dp[j+1][i+1],dp[j-1][i+1]));
           }
        }
        /*这一段是dp后的状态
     for(int i=0;i<=10;i++){
            for(int j=0;j<=t;j++){
                cout<<dp[i][j]<<" ";
            }
            cout<<'
    ';
        }
        */
        cout<<dp[5][0]<<'
    ';
       }
       
     return 0;
    }

    J - 盐水的故事

    挂盐水的时候,如果滴起来有规律,先是滴一滴,停一下;然后滴二滴,停一下;再滴三滴,停一下...,现在有一个问题:这瓶盐水一共有VUL毫升,每一滴是D毫升,每一滴的速度是一秒(假设最后一滴不到D毫升,则花费的时间也算一秒),停一下的时间也是一秒这瓶水什么时候能挂完呢?

    Input输入数据包含多个测试实例,每个实例占一行,由VUL和D组成,其中 0<D<VUL<5000。
    Output对于每组测试数据,请输出挂完盐水需要的时间,每个实例的输出占一行。
    Sample Input
    10 1
    Sample Output
    13
    #include <bits/stdc++.h>
    #define  int long long
    #define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
    const int maxn=1e5+50;
    const int INF=0x3f3f3f3f;
    using namespace std;
    
    signed main(){
          IOS;
      double V,d;
      int time,t;
      while(cin>>V>>d){
          time=0;t=0;
          while(V>0){
              V-=d;
              t++;
          }
          time+=t;
          for(int i=1;;i++){
              if(i>=t)break;
              t-=i;
              time++;
          }
          cout<<time<<'
    ';
      }
     return 0;
    }
     



     
    
    
    
    
  • 相关阅读:
    Async和Await的用法
    Idea有关收藏的博客
    记录看到的写的好的、实用的JavaScript博客
    Linux实用指令一
    flex布局
    移动端开发常用的vue组件
    npm --save 的含义
    切换npm源为淘宝镜像
    java String Map List 转换
    mysql查看被锁住的表
  • 原文地址:https://www.cnblogs.com/ahijing/p/14289919.html
Copyright © 2020-2023  润新知