这几天一直在宿舍跑PY模型,学校的ACM寒假集训我也没去成,来学校的时候已经18号了,突然加进去也就上一天然后排位赛了,没学什么就去打怕是要被虐成渣,今天开学前一天,看到最后有一场大的排位赛,就上去试了一下,果然被虐成渣,十二道题目在有限时间内就做了四道,还有一道疯狂的WA,拿出两道一些有趣的想法出来分享一下。

  今天打题就遇到了大数计算的问题,本来昨晚想解决这个难题,也没来得及,所以打题的时候大数计算那道就放弃了,过几天我一定会扔上来的。

今日兴趣新闻:

年度最惨小学生!在姥姥家热炕头写作业,写完一看字都没了!

https://baijiahao.baidu.com/s?id=1625958926368259758&wfr=spider&for=pc

笑出猪叫声,正映衬现在刚开学前的大学生疯狂的恶补一些零零碎碎的作业和策划书哈哈,话说这个热可擦我也还没玩过呢,老了老了。

------------------------------------------------题目----------------------------------------------------------

Malek and Summer Semester

Malek registered n courses for the summer semester. Malek has a success rate m, which means he has to succeed at least in ceil(n × m) courses out of the n courses, in order to consider the summer semester as a successful semester. Malek is considered successful in the ith course, if his grade on this course was greater than or equal to 50.

ceil(x) is the smallest integer greater than or equal to x. For example, ceil(0.95) = 1, ceil(4) = 4, and ceil(7.001) = 8.

Malek will give you his grades in the n courses, and your task is to tell him whether the summer semester was a successful semester or not.

Input

The first line contains an integer T (1 ≤ T ≤ 100), where T is the number of test cases.

The first line of each test case contains an integer n and a real number m (1 ≤ n ≤ 100) (0 < m < 1), where n is the number of courses, and m is the required success rate.

The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 100), where ai is the grade of the ith course.

The success rate m is given with exactly two digits after the decimal point.

Output

For each test case, print a single line containing "YES" (without quotes), if the summer semester was a successful semester for Malek. Otherwise, print "NO" (without quotes).

Example

input

 0.60

 0.75
    

output

NO
YES

------------------------------------------------题目----------------------------------------------------------

(一) 原题大意:

    Malek 为夏季学期注册了n门课程。马利克拥有成功率,这意味着他至少在成功小区ñ  ×  )课程出的ñ课程,为了考虑夏季学期作为一个成功的学期。马利克被认为是成功的当然,如果他对这个课程成绩大于或等于50。

    ceilx)是大于或等于 x的最小整数。例如, ceil(0.95)= 1, ceil(4)= 4,ceil(7.001)= 8。

    题目很简单,实际上这是一道2017 JUST编程大赛3.0的签到题,拿这道题出来呢是有一个小的细节使用知识点,那就是ceil

(二) AC代码:

#include<iostream>
#include<cmath>
#include<stdio.h>
using namespace std;
int times,number,mark,ok;
float up;
int main()
{
scanf("%d", &times);
for(;times>;times--)
{
scanf("%d %f", &number,&up);
ok = ceil(number*up);
printf("%d",ok);
for(;number>;number--)
{
scanf("%d", &mark);
if(mark>=) ok--;
}
if(ok <= ) printf("YES\n");
else printf("NO\n");
}
return ;
}

(三) 解后分析:

    这道题难度小,如果会用ceil这个函数就特别简单了,ceil(x)这个函数是向上取整函数,如果需要向下取整,还有一个函数是floor(x)

    floor()是向负无穷大舍入,floor(-10.5) == -11;
    ceil()是向正无穷大舍入,ceil(-10.5) == -10

    这是一个细节知识点,可能以后会经常用到呢。

------------------------------------------------题目----------------------------------------------------------

The Architect Omar

Architect Omar is responsible for furnishing the new apartments after completion of its construction. Omar has a set of living room furniture, a set of kitchen furniture, and a set of bedroom furniture, from different manufacturers.

In order to furnish an apartment, Omar needs a living room furniture, a kitchen furniture, and two bedroom furniture, regardless the manufacturer company.

You are given a list of furniture Omar owns, your task is to find the maximum number of apartments that can be furnished by Omar.

Input

The first line contains an integer T (1 ≤ T ≤ 100), where T is the number of test cases.

The first line of each test case contains an integer n (1 ≤ n ≤ 1000), where n is the number of available furniture from all types. Then n lines follow, each line contains a string s representing the name of a furniture.

Each string s begins with the furniture's type, then followed by the manufacturer's name. The furniture's type can be:

  • bed, which means that the furniture's type is bedroom.
  • kitchen, which means that the furniture's type is kitchen.
  • living, which means that the furniture's type is living room.

All strings are non-empty consisting of lowercase and uppercase English letters, and digits. The length of each of these strings does not exceed 50 characters.

Output

For each test case, print a single integer that represents the maximum number of apartments that can be furnished by Omar

Example

Input


bedXs
kitchenSS1
kitchen2
bedXs
living12
livingh

Output

 

------------------------------------------------题目----------------------------------------------------------

(一) 原题大意:

    这道题呢难度也不大,算是签到题,只是有点好玩。原题意思是某个人要建一个公寓,现在需要两张床bed、一个厨房kitchen、一个居室living,才能算是一个公寓,现在给你一堆家居,自带类型+乱七八糟的字符串,让你识别出是什么类型的家具,然后输出可以组成几间公寓。

(二) 题目分析:

    唯一难点可能就是在识别输入的字符串中是否含有某个词语,解题后我翻了一下网上的一些做法,有人干脆就直接判断第0下标的字母'b' 'k' 'l'来区分,感觉这是不严谨的,,还有人用到了string的find函数,这个倒是挺新奇,我还不知道,待会也贴上来学习一下。我的题目做法呢是用strncmp函数,去对比开头是否是所要求的类型,然后再进行计算。打题的时候还发现一些比较有趣的字符串处理函数,如strrev(array);这是反转字符串,等等。

(三) 代码分块:

    第一步:先去获取到每一个家具的类型:

        for(;number>;number--)
{
scanf("%s", name);
if(strncmp(name,"bed",) == ) have[]++;
else if(strncmp(name,"kitchen",) == ) have[]++;
else if(strncmp(name,"living",) == ) have[]++;
}

    我是这么做的,对比前面字母是否相同,然后获取。

    第二步,计算最大拥有几个公寓:

        while()
{
if(have[] < || have[] == || have[] == ) break;
have[]-=;
have[]--;
have[]--;
ok++;
}

(四) AC代码:

#include<iostream>
#include<cstring>
#include<stdio.h>
using namespace std;
int times,number,have[],ok;
char name[];
float up;
int main()
{
scanf("%d", &times);
for(;times>;times--)
{
have[] = have[] = have[] = ok = ;
scanf("%d %f", &number);
for(;number>;number--)
{
scanf("%s", name);
if(strncmp(name,"bed",) == ) have[]++;
else if(strncmp(name,"kitchen",) == ) have[]++;
else if(strncmp(name,"living",) == ) have[]++;
}
while()
{
if(have[] < || have[] == || have[] == ) break;
have[]-=;
have[]--;
have[]--;
ok++;
}
printf("%d",ok);
}
return ;
}

(五)AC截图:

(六) 解后分析:

    题目不难,直接判断首字母也能过,翻看别人的题解的时候发现一个string的某个用法,可能感觉挺有用,贴出来学习一下:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
int t,n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
int num1=,num2=,num3=;
for(int i=;i<n;i++){
string s;
cin>>s;
if(s.find("bed")==)num1++;
if(s.find("kitchen")==)num2++;
if(s.find("living")==)num3++;
}
//cout<<num1<<" "<<num2<<" "<<num3<<endl;
int ans=min(num1/,min(num2,num3));
printf("%d\n",ans);
}
return ;
}

    该题解使用了string类,并使用了string的find函数,这个函数可以查找字符串中特定的字符串内容。为了拓展这个知识点,我还找到了下面一些有趣的函数原型:

    注:以下所讲的所有的string查找函数,都有唯一的返回类型,那就是size_type,即一个无符号整数(按打印出来的算)。若查找成功,返回按查找规则找到的第一个字符或子串的位置;若查找失败,返回npos,即-1(打印出来为4294967295)。

    (1)find()

//string (1)
size_type find (const basic_string& str, size_type pos = ) const noexcept;
//c-string (2)
size_type find (const charT* s, size_type pos = ) const;
//buffer (3)
size_type find (const charT* s, size_type pos, size_type n) const;
//character (4)
size_type find (charT c, size_type pos = ) const noexcept;

    这个也就是上面代码所使用了的了,后面的参数可以省略。

    (2)rfind()

//string (1)
size_type rfind (const basic_string& str, size_type pos = npos) const noexcept;
//c-string (2)
size_type rfind (const charT* s, size_type pos = npos) const;
//buffer (3)
size_type rfind (const charT* s, size_type pos, size_type n) const;
//character (4)
size_type rfind (charT c, size_type pos = npos) const noexcept;

     rfind()与find()很相似,差别在于查找顺序不一样,rfind()是从指定位置起向前查找,直到串首。例如,上例中的st1.rfind('a',7)一句,就是从st1的位置7(st1的最后一个字符b)开始查找字符a,第一次找到的是倒数第2个字符a,所以返回6。

    (3)find_first_of()

//string (1)
size_type find_first_of (const basic_string& str, size_type pos = ) const noexcept;
//c-string (2)
size_type find_first_of (const charT* s, size_type pos = ) const;
//buffer (3)
size_type find_first_of (const charT* s, size_type pos, size_type n) const;
//character (4)
size_type find_first_of (charT c, size_type pos = ) const noexcept;

    在源串中从位置pos起往后查找,只要在源串中遇到一个字符,该字符与目标串中任意一个字符相同,就停止查找,返回该字符在源串中的位置;若匹配失败,返回npos。

    (4) find_last_of()

//string (1)
size_type find_last_of (const basic_string& str, size_type pos = npos) const noexcept;
//c-string (2)
size_type find_last_of (const charT* s, size_type pos = npos) const;
//buffer (3)
size_type find_last_of (const charT* s, size_type pos, size_type n) const;
//character (4)
size_type find_last_of (charT c, size_type pos = npos) const noexcept;

    该函数与find_first_of()函数相似,只不过查找顺序是从指定位置向前。

    (5)find_first_not_of()

//string (1)
size_type find_first_not_of (const basic_string& str, size_type pos = ) const noexcept;
//c-string (2)
size_type find_first_not_of (const charT* s, size_type pos = ) const;
//buffer (3)
size_type find_first_not_of (const charT* s, size_type pos, size_type n) const;
//character(4)
size_type find_first_not_of (charT c, size_type pos = ) const noexcept;

    在源串中从位置pos开始往后查找,只要在源串遇到一个字符,该字符与目标串中的任意一个字符都不相同,就停止查找,返回该字符在源串中的位置;若遍历完整个源串,都找不到满  足条件的字符,则返回npos。

    注:同理也有find_last_not_of()

注:如果有更好的解法,真心希望您能够评论留言贴上您的代码呢~互相帮助互相鼓励才能成长鸭~~

『ACM C++』Virtual Judge | 两道基础题 - The Architect Omar && Malek and Summer Semester的更多相关文章

  1. Java基础知识强化11:多态的两道基础题

    1.第1题 class Base { public void method() { System.out.print("Base method"); } } class Child ...

  2. 各位大佬Python的第一部分道基础题已经整理好了,希望大家面试的时候能用的上。

    Python的第一部分道基础题,希望大家面试的时候能用的上. 1.为什么学习Python? Python是目前市面上,我个人认为是最简洁.最优雅.最有前途.最全能的编程语言,没有之一. 2.通过什么途 ...

  3. 『ACM C++』 Codeforces | 1066A - Points in Segments

    大一生活真 特么 ”丰富多彩“ ,多彩到我要忙到哭泣,身为班长,很多班级的事情需要管理,也是,什么东西都得体验学一学,从学生会主席.团委团总支.社团社长都体验过一番了,现在差个班长也没试过,就来体验了 ...

  4. ACM/ICPC 之 Floyd范例两道(POJ2570-POJ2263)

    两道以Floyd算法为解法的范例,第二题如果数据量较大,须采用其他解法 POJ2570-Fiber Network //经典的传递闭包问题,由于只有26个公司可以采用二进制存储 //Time:141M ...

  5. ACM/ICPC 之 SPFA范例两道(POJ3268-POJ3259)

    两道以SPFA算法求解的最短路问题,比较水,第二题需要掌握如何判断负权值回路. POJ3268-Silver Cow Party //计算正逆最短路径之和的最大值 //Time:32Ms Memory ...

  6. 『ACM C++』PTA浙大 | 基础题 - Have Fun with Numbers

    连着这两道都是开学前数构老师的“爱心作业”,还没上课开学就给我们布置作业了,这道题有点小坑,也经常遇到类似的问题,特地拿出来记录一下. -------------------------------- ...

  7. 『ACM C++』 PTA 天梯赛练习集L1 | 029-033

    哈哈,今天开始我也是学车人了~ 开始一千多道疯狂刷题~ ------------------------------------------------L1-029------------------ ...

  8. 『ACM C++』 PTA 天梯赛练习集L1 | 007-011

    真的是忙头晕了,学业.ACM打题.班级活动.自学新东西,哇这充实的大学~ ------------------------------------------------L1-007--------- ...

  9. 『ACM C++』HDU杭电OJ | 1418 - 抱歉 (拓扑学:多面体欧拉定理引申)

    呕,大一下学期的第一周结束啦,一周过的挺快也挺多出乎意料的事情的~ 随之而来各种各样的任务也来了,嘛毕竟是大学嘛,有点上进心的人多多少少都会接到不少任务的,忙也正常啦~端正心态 开心面对就好啦~ 今天 ...

随机推荐

  1. python-requests 简单实现数据抓取

    安装包: requests,lxmlrequest包用于进行数据抓取,lxml用来进行数据解析对于对网页内容的处理,由于html本身并非如数据库一样为结构化的查询所见即所得,所以需要对网页的内容进行分 ...

  2. Jquery系列:checkbox 获取值、选中、设置值、事件监听等操作

    <div id="divId" class="divTable"> <div class="tableBody"> ...

  3. 深入理解读写锁—ReadWriteLock源码分析

    转载:https://blog.csdn.net/qq_19431333/article/details/70568478 ReadWriteLock管理一组锁,一个是只读的锁,一个是写锁.读锁可以在 ...

  4. 今日头条极速版邀请码以及其它APP邀请码大全

    现在大多手机新闻APP都需要输入码,在网上找了很久,最终找到一个比较全的文章,本人试过,都是可以使用的! 第1个比较好,可边看新闻,边收益!嘻嘻!平时写代码累了,休息刷一下!或者在睡觉前刷新一下,每天 ...

  5. 转:什么是4D(DRG、DLG、DOM、DEM)数据?

    ps:摘抄地址http://blog.163.com/wangqing_rs/blog/static/16451519120111026102916472/  什么是4D(DRG.DLG.DOM.DE ...

  6. Siebel计划和实施

    1.计划: 自上而下计划配置项目 1)首先,确定UI和应用产品功能 2)然后,确定为实现UI功能而需要在业务层所做的更改 3)最后,确定为实现业务层更改而需要在数据层所做的更改---尽可能少做更改 如 ...

  7. 爬虫入门之handler与opener(三)

    1 自定义opener opener是 urllib.request.OpenerDirector 的实例,我们之前一直都在使用的urlopen,它是一个特殊的模块构建好的opener 但是基本的ur ...

  8. django模型详解(四)

    1 概述 (1)概述 : Django对各种数据库提供了很好的支持,Django为这些数据库提供了统一的调用API,根据不同的业务需求选择不同的数据库 (2)定义模型 模型,属性,表,字段间的关系 一 ...

  9. PHP程序员应当如何保持与时俱进?

    记得之前在某个论坛上看到别人说php程序员土,作为一名php程序员内心当然是不乐意的.不过别人这么说也不是完全没有道理,其实他说php程序员土应该指的就是php程序员不懂得与时俱进. 当然,这也不全是 ...

  10. 一点一点学写Makefile(3)-增加第三方库和头文件

    我们在写代码的时候不一定都是有自己来完成,一个工程中会大量使用一些比较优秀的动态库.静态库等,我们在使用这些库完成所有的代码后,需要在编译的时候将这些库使用的头文件添加到我们的工程上,将他的库文件也添 ...