2018年第四阶段组队训练赛第十场-程序员宅基地

A: Taro's Shopping

Mammy decided to give Taro his first shopping experience. Mammy tells him to choose any two items he wants from those listed in the shopping catalogue, but Taro cannot decide which two, as all the items look attractive. Thus he plans to buy the pair of two items with the highest price sum, not exceeding the amount Mammy allows. As getting two of the same item is boring, he wants two different items. 

You are asked to help Taro select the two items. The price list for all of the items is given. Among pairs of two items in the list, find the pair with the highest price sum not exceeding the allowed amount, and report the sum. Taro is buying two items, not one, nor three, nor more. Note that, two or more items in the list may be priced equally. 

 

输入
The input consists of multiple datasets, each in the following format. 
n m
a1 a2 … an 
A dataset consists of two lines. In the first line, the number of items n and the maximum payment allowed m are given. n is an integer satisfying 2 ≤ n ≤ 1000. m is an integer satisfying 2 ≤ m ≤ 2,000,000. In the second line, prices of n items are given. ai (1 ≤ i ≤ n) is the price of the i-th item. This value is an integer greater than or equal to 1 and less than or equal to 1,000,000. 
The end of the input is indicated by a line containing two zeros. The sum of n's of all the datasets does not exceed 50,000. 
 

 

输出
For each dataset, find the pair with the highest price sum not exceeding the allowed amount m and output the sum in a line. If the price sum of every pair of items exceeds m, output NONE instead. 

 

样例输入
3 45
10 20 30
6 10
1 2 5 8 9 11
7 100
11 34 83 47 59 29 70
4 100
80 70 60 50
4 20
10 5 10 16
0 0

 

样例输出
40
10
99
NONE
20


#include <bits/stdc++.h>
 
using namespace std;
bool cmp(int x,int y)
{
    return x>y;
}
int n,m,a[1005];
int main()
{
    while(1)
    {
        scanf("%d%d",&n,&m);
        if(n==0&&m==0)
            return 0;
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        sort(a,a+n,cmp);
            int flag=0,ans=-1;
            for(int i=0;i<n;i++)
            {
                for(int j=i+1;j<n;j++)
                {
                    if(a[i]+a[j]<=m)
                    {
                        ans=max(ans,a[i]+a[j]);
 
                    }
                }
            }
            if(ans==-1)
            {
                printf("NONE\n");
            }
            else
            {
                printf("%d\n",ans);
            }
    }
//    cout << "Hello world!" << endl;
    return 0;
}
 

问题 B: Almost Identical Programs


题目描述
The programming contest named Concours de Programmation Comtemporaine Interuniversitaire (CPCI) has a judging system similar to that of ICPC; contestants have to submit correct outputs for two different inputs to be accepted as a correct solution. Each of the submissions should include the program that generated the output. A pair of submissions is judged to be a correct solution when, in addition to the correctness of the outputs, they include an identical program. 

Many contestants, however, do not stop including a different version of their programs in their second submissions, after modifying a single string literal in their programs representing the input file name, attempting to process different input. The organizers of CPCI are exploring the possibility of showing a special error message for such close submissions, indicating contestants what's wrong with such submissions. Your task is to detect such close submissions. 
 

 

输入
The input consists of at most 100 datasets, each in the following format. 
s1 
s2 
Each of s1 and s2 is a string written in a line, with the length between 1 and 200, inclusive. They are the first and the second submitted programs respectively. A program consists of lowercase letters (a, b, ..., z), uppercase letters (A, B, ..., Z), digits (0, 1, ..., 9), double quotes ("), and semicolons (;). When double quotes occur in a program, there are always even number of them.  
The end of the input is indicated by a line containing one ‘.’ (period). 
 

 

输出
For each dataset, print the judge result in a line. 
If the given two programs are identical, print IDENTICAL. If two programs differ with only one corresponding string literal, print CLOSE. Otherwise, print DIFFERENT. A string literal is a possibly empty sequence of characters between an odd-numbered occurrence of a double quote and the next occurrence of a double quote. 
 

 

样例输入
print"hello";print123
print"hello";print123
read"B1input";solve;output;
read"B2";solve;output;
read"C1";solve;output"C1ans";
read"C2";solve;output"C2ans";
""""""""
"""42"""""
slow"program"
fast"code"
"super"fast"program"
"super"faster"program"
X""
X
I"S""CREAM"
I"CE""CREAM"
11"22"11
1"33"111
.

 

样例输出
IDENTICAL
CLOSE
DIFFERENT
CLOSE
DIFFERENT
DIFFERENT
DIFFERENT
CLOSE
DIFFERENT
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
char str1[220],str2[220];
int main()
{
    //freopen("in.txt","r",stdin);
    while(1)
    {
        scanf("%s",str1);
        if(str1[0]=='.')
        {
            break;
        }
        scanf("%s",str2);
        int dif=0,cnt=0;
        int len1=strlen(str1),len2=strlen(str2);
        int i,j;
        int flag=0;
        for(i=0,j=0; i<len1&&j<len2; i++,j++)
        {

            if(str1[i]!=str2[j]&&cnt==0)
            {

                printf("DIFFERENT\n");
                flag=1;
                break;

            }
            else if(str1[i]!=str2[j]&&cnt==1)
            {
                dif++;
                if(dif==2)
                {
                    printf("DIFFERENT\n");
                    flag=1;
                    break;
                }
                while(str1[i]!='"')
                {
                    i++;
                }
                while(str2[j]!='"')
                {
                    j++;
                }
            }
            if(str1[i]==str2[j]&&str1[i]=='"')
            {
                cnt++;
                if(cnt==2)
                {
                    cnt=0;
                }
            }
        }
        if(i==len1&&j==len2)
        {
            if(dif==0)
            {
                printf("IDENTICAL\n");
            }
            else if(dif==1)
            {
                printf("CLOSE\n");
            }
        }
        else
        {
            if(flag==0)
            {
                printf("DIFFERENT\n");
            }
        }
    }
    return 0;
}
 
题目描述
Mr. Gardiner is a modern garden designer who is excellent at utilizing the terrain features. His design method is unique: he first decides the location of ponds and design them with the terrain features intact. 
According to his unique design procedure, all of his ponds are rectangular with simple aspect ratios. First, Mr. Gardiner draws a regular grid on the map of the garden site so that the land is divided into cells of unit square, and annotates every cell with its elevation. In his design method, a pond occupies a rectangular area consisting of a number of cells. Each of its outermost cells has to be higher than all of its inner cells. For instance, in the following grid map, in which numbers are elevations of cells, a pond can occupy the shaded area, where the outermost cells are shaded darker and the inner cells are shaded lighter. You can easily see that the elevations of the outermost cells are at least three and those of the inner ones are at most two. 
A rectangular area on which a pond is built must have at least one inner cell. Therefore, both its width and depth are at least three.  
When you pour water at an inner cell of a pond, the water can be kept in the pond until its level reaches that of the lowest outermost cells. If you continue pouring, the water inevitably spills over. Mr. Gardiner considers the larger capacity the pond has, the better it is. Here, the capacity of a pond is the maximum amount of water it can keep. For instance, when a pond is built on the shaded area in the above map, its capacity is (3 − 1) + (3 − 0) + (3 − 2) = 6, where 3 is the lowest elevation of the outermost cells and 1, 0, 2 are the elevations of the inner cells. Your mission is to write a computer program that, given a grid map describing the elevation of each unit square cell, calculates the largest possible capacity of a pond built in the site. 
Note that neither of the following rectangular areas can be a pond. In the left one, the cell at the bottom right corner is not higher than the inner cell. In the right one, the central cell is as high as the outermost cells. 

 

输入
The input consists of at most 100 datasets, each in the following format. 
d w 
e1, 1 ... e1, w 
 ... 
ed, 1 ... ed, w 
The first line contains d and w, representing the depth and the width, respectively, of the garden site described in the map. They are positive integers between 3 and 10, inclusive. Each of the following d lines contains w integers between 0 and 9, inclusive, separated by a space. The x-th integer in the y-th line of the d lines is the elevation of the unit square cell with coordinates (x, y). 
The end of the input is indicated by a line containing two zeros separated by a space. 

 

输出
For each dataset, output a single line containing the largest possible capacity of a pond that can be built in the garden site described in the dataset. If no ponds can be built, output a single line containing a zero. 

 

样例输入
3 3
2 3 2
2 1 2
2 3 1
3 5
3 3 4 3 3
3 1 0 2 3
3 3 4 3 2
7 7
1 1 1 1 1 0 0
1 0 0 0 1 0 0
1 0 1 1 1 1 1
1 0 1 0 1 0 1
1 1 1 1 1 0 1
0 0 1 0 0 0 1
0 0 1 1 1 1 1
6 6
1 1 1 1 2 2
1 0 0 2 0 2
1 0 0 2 0 2
3 3 3 9 9 9
3 0 0 9 0 9
3 3 3 9 9 9
0 0

 

样例输出
0
3
1
9


#include <bits/stdc++.h>
 
using namespace std;
 
int Map[15][15];
int n,m;
 
int cal(int nn,int mm,int k,int p)
{
    int Min = 100;
    for(int  i=k;i<k+nn;i++)
    {
        Min = min(Map[i][p],Min);
        Min = min(Map[i][p+mm-1],Min);
    }
    for(int i=p;i<p+mm;i++)
    {
        Min = min(Map[k][i],Min);
        Min = min(Map[k+nn-1][i],Min);
    }
    int anst = 0;
    for(int i=k+1;i<k+nn-1;i++)
    {
        for(int j=p+1;j<p+mm-1;j++)
        {
            if(Map[i][j]>=Min)
                return 0;
            anst+=(Min-Map[i][j]);
        }
    }
    return anst;
}
 
int main()
{
 
    while(scanf("%d%d",&n,&m))
    {
        if(n==0&&m==0)
            break;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
                scanf("%d",&Map[i][j]);//>>Map[i][j];
 
        int ans = 0;
 
        for(int i=3;i<=n;i++)
        {
            for(int j=3;j<=m;j++)
            {
                for(int k=1;i+k-1<=n;k++)
                {
                    for(int p=1;p+j-1<=m;p++)
                    {
                        ans = max(ans,cal(i,j,k,p));
                        //cout<<cal(i,j,k,p)<<endl;
                    }
                }
            }
        }
        printf("%d\n",ans);
    }
}

 

 

问题 F: Folding a Ribbon


Think of repetitively folding a very long and thin ribbon. First, the ribbon is spread out from left to right, then it is creased at its center, and one half of the ribbon is laid over the other. You can either fold it from the left to the right, picking up the left end of the ribbon and laying it over the right end, or from the right to the left, doing the same in the reverse direction. To fold the already folded ribbon, the whole layers of the ribbon are treated as one thicker ribbon, again from the left to the right or the reverse. 
After folding the ribbon a number of times, one of the layers of the ribbon is marked, and then the ribbon is completely unfolded restoring the original state. Many creases remain on the unfolded ribbon, and one certain part of the ribbon between two creases or a ribbon end should be found marked. Knowing which layer is marked and the position of the marked part when the ribbon is spread out, can you tell all the directions of the repeated folding, from the left or from the right? 
The figure below depicts the case of the first dataset of the sample input. 


输入
The input consists of at most 100 datasets, each being a line containing three integers. 
n i j
The three integers mean the following: The ribbon is folded n times in a certain order; then, the i-th layer of the folded ribbon, counted from the top, is marked; when the ribbon is unfolded completely restoring the original state, the marked part is the j-th part of the ribbon separated by creases, counted from the left. Both i and j are one-based, that is, the topmost layer is the layer 1 and the leftmost part is numbered 1. These integers satisfy 1 ≤ n ≤ 60, 1 ≤ i ≤ 2n, and 1 ≤ j ≤ 2n. 
The end of the input is indicated by a line with three zeros. 
 


输出
For each dataset, output one of the possible folding sequences that bring about the result specified in the dataset. 
The folding sequence should be given in one line consisting of n characters, each being either L or R. L means a folding from the left to the right, and R means from the right to the left. The folding operations are to be carried out in the order specified in the sequence. 
 


样例输入
3 3 2
12 578 2214
59 471605241352156968 431565444592236940
0 0 0
 
样例输出
LRR
RLLLRRRLRRLL
LRRRLRRLLRRRRLLLLRLLRRRLRRLLRLLLLLLRLRLLRLRLLLRLRLLRLLRRRLL

参考:https://blog.csdn.net/winter2121/article/details/82344071

分析:很巧妙的一道题 先从最后叠起到展开
1.你可以先看i,看i在当前被子的上半部还是下半部,如果是上半部,则需要翻开,下半部,则是被压着的那部分。每次判断上下部分,并记录n次,每次更新原本i层现在是几层。
2.现在你已经知道怎么叠的了(该次是被压着 还是要盖着另一半) 然后就要看方向 如果j在需要盖着并在左半部分 则需要从右半部分盖过来 则是“R” 然后更新j 以此类推(在右半部分的j的更新需要在更新处注意)

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
ll pow_2[62];

void init()
{
    pow_2[0] = 1;
    for(int i=1;i<=61;i++)
    {
        pow_2[i] = pow_2[i-1]<<1;
    }
}

int main()
{
    init();
    long long int n,x,y;
    bool flag[65];
    while(cin>>n>>x>>y)
    {
        if(n==0&&x==0&&y==0)
            break;

        for(int i=n;i>0;i--)
        {
            if(x>pow_2[i-1]) //ya zhe
            {
                flag[i] = 1;
                x -= pow_2[i-1];
            }
            else //xian kai
            {
                flag[i] = 0;
                x = pow_2[i-1]+1-x;
            }
        }

        for(int i=1;i<=n;i++)
        {
            if(y<=pow_2[n-i])
            {
                if(flag[i]) //ya zhe
                    printf("R");
                else
                {
                    printf("L");
                    y = pow_2[n-i] +1 -y;
                }
            }
            else
            {
                if(flag[i])
                {
                    printf("L");
                    y-=pow_2[n-i];
                }
                else
                {
                    printf("R");
                    y = pow_2[n-i+1]+1-y;
                }
            }
        }
        printf("\n");
    }
    return 0;
}

 

 

转载于:https://www.cnblogs.com/hao-tian/p/9582564.html

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_30462049/article/details/98930450

智能推荐

【新手科研指南5】深度学习代码怎么读-小白阶段性思路(以手写数字识别应用为例)_深度学习程序怎么读-程序员宅基地

文章浏览阅读6.2k次,点赞6次,收藏26次。我是一个深度学习代码小白,请你用中文写上注释,能让我能轻松理解下面这段代码。注意包含所有函数、调用和参数的注释。以同样的python代码块样式返回你写的代码给我。代码看累了,就看《动手学深度学习》文档:基于PyTorch框架,从底层函数实现基础功能,再到框架的高级功能。努力上路的小白一枚,麻烦路过的大佬指导一二,同时希望能和大家交流学习~争取更新学习这个文档的专栏,记录学习过程。量身定做了一套话术hhh,亲身测试还不错。这个感觉更浅一点儿,之后复习看吧。20天吃掉那只Pytorch。_深度学习程序怎么读

Java学习路线图,看这一篇就够了!-程序员宅基地

文章浏览阅读2.7w次,点赞126次,收藏1.2k次。耗废1024根秀发,Java学习路线图来了,整合了自己所学的所有技术整理出来的2022最新版Java学习路线图,适合于初、中级别的Java程序员。_java学习路线

PCL_Tutorial2-1.7-点云保存PNG_pcl::io:savepng-程序员宅基地

文章浏览阅读4.4k次。1.7-savingPNG介绍代码详情函数详解savePNGFile()源码savePNGFile()源码提示savePNGFile()推荐用法处理结果代码链接介绍PCL提供了将点云的值保存到PNG图像文件的可能性。这只能用有有序的云来完成,因为结果图像的行和列将与云中的行和列完全对应。例如,如果您从类似Kinect或Xtion的传感器中获取了点云,则可以使用它来检索与该云匹配的640x480 RGB图像。代码详情#include <pcl / io / pcd_io.h>#incl_pcl::io:savepng

知乎问答:程序员在咖啡店编程,喝什么咖啡容易吸引妹纸?-程序员宅基地

文章浏览阅读936次。吸引妹子的关键点不在于喝什么咖啡,主要在于竖立哪种男性人设。能把人设在几分钟内快速固定下来,也就不愁吸引对口的妹子了。我有几个备选方案,仅供参考。1. 运动型男生左手单手俯卧撑,右手在键盘上敲代码。你雄壮的腰腹肌肉群活灵活现,简直就是移动的春药。2.幽默男生花 20 块找一个托(最好是老同学 or 同事)坐你对面。每当你侃侃而谈,他便满面涨红、放声大笑、不能自已。他笑的越弱_咖啡厅写代码

【笔试面试】腾讯WXG 面委会面复盘总结 --一次深刻的教训_腾讯面委会面试是什么-程序员宅基地

文章浏览阅读1.2w次,点赞5次,收藏5次。今天 (应该是昨天了,昨晚太晚了没发出去)下午参加了腾讯WXG的面委会面试。前面在牛客上搜索了面委会相关的面经普遍反映面委会较难,因为都是微信的核心大佬,问的问题也会比较深。昨晚还蛮紧张的,晚上都没睡好。面试使用的是腾讯会议,时间到了面试官准时进入会议。照例是简单的自我介绍,然后是几个常见的基础问题:例如数据库索引,什么时候索引会失效、设计模式等。这部分比较普通,问的也不是很多,不再赘述。现在回想下,大部分还是简历上写的技能点。接下来面试官让打开项目的代码,对着代码讲解思路。我笔记本上没有这部分代码,所_腾讯面委会面试是什么

AI绘画自动生成器:艺术创作的新浪潮-程序员宅基地

文章浏览阅读382次,点赞3次,收藏4次。AI绘画自动生成器是一种利用人工智能技术,特别是深度学习算法,来自动创建视觉艺术作品的软件工具。这些工具通常基于神经网络模型,如生成对抗网络(GANs),通过学习大量的图像数据来生成新的图像。AI绘画自动生成器作为艺术与科技结合的产物,正在开启艺术创作的新篇章。它们不仅为艺术家和设计师提供了新的工具,也为普通用户提供了探索艺术的机会。随着技术的不断进步,我们可以预见,AI绘画自动生成器将在未来的创意产业中发挥越来越重要的作用。

随便推点

Flutter ListView ListView.build ListView.separated_flutter listview.separated和listview.builder-程序员宅基地

文章浏览阅读1.7k次。理解为ListView 的三种形式吧ListView 默认构造但是这种方式创建的列表存在一个问题:对于那些长列表或者需要较昂贵渲染开销的子组件,即使还没有出现在屏幕中但仍然会被ListView所创建,这将是一项较大的开销,使用不当可能引起性能问题甚至卡顿直接返回的是每一行的Widget,相当于ios的row。行高按Widget(cell)高设置ListView.build 就和io..._flutter listview.separated和listview.builder

2021 最新前端面试题及答案-程序员宅基地

文章浏览阅读1.4k次,点赞4次,收藏14次。废话不多说直接上干货1.js运行机制JavaScript单线程,任务需要排队执行同步任务进入主线程排队,异步任务进入事件队列排队等待被推入主线程执行定时器的延迟时间为0并不是立刻执行,只是代表相比于其他定时器更早的被执行以宏任务和微任务进一步理解js执行机制整段代码作为宏任务开始执行,执行过程中宏任务和微任务进入相应的队列中整段代码执行结束,看微任务队列中是否有任务等待执行,如果有则执行所有的微任务,直到微任务队列中的任务执行完毕,如果没有则继续执行新的宏任务执行新的宏任务,凡是在..._前端面试

linux基本概述-程序员宅基地

文章浏览阅读1k次。(3)若没有查到,则将请求发给根域DNS服务器,并依序从根域查找顶级域,由顶级查找二级域,二级域查找三级,直至找到要解析的地址或名字,即向客户机所在网络的DNS服务器发出应答信息,DNS服务器收到应答后现在缓存中存储,然后,将解析结果发给客户机。(3)若没有查到,则将请求发给根域DNS服务器,并依序从根域查找顶级域,由顶级查找二级域,二级域查找三级,直至找到要解析的地址或名字,即向客户机所在网络的DNS服务器发出应答信息,DNS服务器收到应答后现在缓存中存储,然后,将解析结果发给客户机。_linux

JavaScript学习手册十三:HTML DOM——文档元素的操作(一)_javascript学习手册十三:html dom——文档元素的操作(一)-程序员宅基地

文章浏览阅读7.9k次,点赞26次,收藏66次。HTML DOM——文档元素的操作1、通过id获取文档元素任务描述相关知识什么是DOM文档元素节点树通过id获取文档元素代码文件2、通过类名获取文档元素任务描述相关知识通过类名获取文档元素代码文件3、通过标签名获取文档元素任务描述相关知识通过标签名获取文档元素获取标签内部的子元素代码文件4、html5中获取元素的方法一任务描述相关知识css选择器querySelector的用法代码文件5、html5中获取元素的方法二任务描述相关知识querySelectorAll的用法代码文件6、节点树上的操作任务描述相关_javascript学习手册十三:html dom——文档元素的操作(一)

《LeetCode刷题》172. 阶乘后的零(java篇)_java 给定一个整数n,返回n!结果尾数中零的数量-程序员宅基地

文章浏览阅读132次。《LeetCode学习》172. 阶乘后的零(java篇)_java 给定一个整数n,返回n!结果尾数中零的数量

php 公众号消息提醒,如何开启公众号消息提醒功能-程序员宅基地

文章浏览阅读426次。请注意,本文将要给大家分享的并不是开启公众号的安全操作风险提醒,而是当公众号粉丝给公众号发消息的时候,公众号的管理员和运营者如何能在手机上立即收到消息通知,以及在手机上回复粉丝消息。第一步:授权1、在微信中点击右上角+,然后选择“添加朋友”,然后选择“公众号”,然后输入“微小助”并关注该公众号。2、进入微小助公众号,然后点击底部菜单【新增授权】,如下图所示:3、然后会打开一个温馨提示页面。请一定要..._php微信公众号服务提示

推荐文章

热门文章

相关标签