记录Codeforces刷题QAQ


一、Theatre Square

题面翻译

用 $ a \times a$ 的石板覆盖 $n \times m $ 的长方形广场,允许石板覆盖的区域超出广场,不允许打破石板,石板的两侧应平行于广场两侧,要求覆盖完广场所需的石板数量最少是多少。

感谢 @Loner_Knowledge 贡献翻译。

题目描述

Theatre Square in the capital city of Berland has a rectangular shape with the size $ n×m $ meters. On the occasion of the city’s anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size $ a×a $ .

What is the least number of flagstones needed to pave the Square? It’s allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It’s not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.

输入格式

The input contains three positive integer numbers in the first line: $ n,m $ and $ a $ ( $ 1\leq n,m,a\leq10^{9} $ ).

输出格式

Write the needed number of flagstones.

样例 #1

样例输入 #1

6 6 4

样例输出 #1

4

提示

CF 题目提交时的注意事项:

CodeForces 不允许多次提交同样的代码。如果您如此提交将会产生提交失败错误。如您确实需要这么做,请自行添加一些注释。

代码如下:

#include<string.h>
#include<stdio.h>
#include<math.h>
#include <stdlib.h>int main()
{long long n, m, a;//输入数值 scanf("%lld%lld%lld",&n,&m,&a);long long  x = n/a, y = m/a;//边长 if(n%a != 0)x++;if(m%a != 0)y++;printf("%lld\n",x*y); return 0;
}

二、 Watermelon

题面翻译

判断输入的正整数能否分成两个正偶数,能则输出YES,不能则输出NO

题目描述

One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed $ w $ kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.

Pete and Billy are great fans of even numbers, that’s why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that’s why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.

输入格式

The first (and the only) input line contains integer number $ w $ ( $ 1<=w<=100 $ ) — the weight of the watermelon bought by the boys.

输出格式

Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.

样例 #1

样例输入 #1

8

样例输出 #1

YES

提示

For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).

代码如下:

#include<string.h>
#include<stdio.h>
#include<math.h>
#include <stdlib.h>int main()
{int n;scanf("%d",&n);if(n%2 == 0&& n != 2){printf("YES\n");}else{printf("NO\n");}return 0;
}

三、Chat Server’s Outgoing Traffic

题面翻译

Polycarp正在开发一个名为“Polychat”的新项目。按照IT的现代倾向,他决定,这个项目也应该包含聊天。为了实现这一目标,Polycarp在笔记本电脑前花费了几个小时,实现了一个可以处理三种命令的聊天服务器:

将一个人加入聊天(“添加”命令)。

从聊天中删除一个人(“删除”命令)。

向所有正在聊天的人发送消息,包括发送消息的人(“发送”命令)。

现在,Polycarp希望了解处理特定命令集时服务器将产生的传出流量。

Polycarp知道聊天服务器不会为“添加”和“删除”命令发送流量。当处理“发送”命令时,服务器向聊天的每个参与者(当前在线的人)发送l个字节,其中l是消息的长度。

由于Polycarp没有时间,他在寻求帮助来解决这个问题。

输入格式

输入文件将包含不超过100个命令,每个命令都在自己的行中。每行不超过100个字符。命令的格式如下:

+<名称>为“添加”命令。
-<名称>为“删除”命令。
<SENDER_NAME>:<MESSAGE_TEXT>为’发送’命令。

(名字)和<sender_name>是拉丁字母和数字的非空序列。<message_text>可以包含字母,数字和空格,但不能以空格开始或结束<message_text>是一个空行。

保证输入数据是正确的,即不会有“添加”命令,如果人用这样的名字已经在聊天,不会有“删除”命令,如果没有人跟在这样的名字聊天等

所有的名字都是区分大小写的。

输出格式

输出流量

Translated by @liyifeng

题目描述

Polycarp is working on a new project called “Polychat”. Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:

  • Include a person to the chat (‘Add’ command).
  • Remove a person from the chat (‘Remove’ command).
  • Send a message from a person to all people, who are currently in the chat, including the one, who sends the message (‘Send’ command).

Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.

Polycarp knows that chat server sends no traffic for ‘Add’ and ‘Remove’ commands. When ‘Send’ command is processed, server sends $ l $ bytes to each participant of the chat, where $ l $ is the length of the message.

As Polycarp has no time, he is asking for your help in solving this problem.

输入格式

Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following:

  • + for ‘Add’ command.
  • - for ‘Remove’ command.
  • <sender_name>:<message_text> for ‘Send’ command.

and <sender_name> is a non-empty sequence of Latin letters and digits. <message_text> can contain letters, digits and spaces, but can’t start or end with a space. <message_text> can be an empty line.

It is guaranteed, that input data are correct, i.e. there will be no ‘Add’ command if person with such a name is already in the chat, there will be no ‘Remove’ command if there is no person with such a name in the chat etc.

All names are case-sensitive.

输出格式

Print a single number — answer to the problem.

样例 #1

样例输入 #1

+Mike
Mike:hello
+Kate
+Dmitry
-Dmitry
Kate:hi
-Kate

样例输出 #1

9

样例 #2

样例输入 #2

+Mike
-Mike
+Mike
Mike:Hi   I am here
-Mike
+Kate
-Kate

样例输出 #2

14

代码如下:

#include<stdio.h>
#include<string.h>
char str[110];
int main()
{int num=0;//记录在线人数int sum=0;//记录最终字节数int ans;//记录冒号的位置while(gets(str)){if(str[0]=='+')num++;else if(str[0]=='-')num--;else{for(int i=0; i<strlen(str); i++){if(str[i]==':'){ans=i;break;}}sum+=(strlen(str)-1-ans)*num;}}printf("%d\n",sum);return 0;
}

四、Triangle

题面翻译

题目描述

给定 444 根木棍的长度,如果它们中存在 333 根木棍可以组成三角形,输出 TRIANGLE;如果它们无法组成三角形,但是它们中存在 333 根木棍可以组成退化的三角形(任意两边之和大于等于第三边,但是不是三角形),输出 SEGMENT;否则,输出 IMPOSSIBLE

注意: 木棍不能折断,也不能只用一部分长度。

输入格式

一行 444 个整数,444 根木棍的长度。

输出格式

如果它们中存在 333 根木棍可以组成三角形,输出 TRIANGLE;如果它们无法组成三角形,但是它们中存在3根木棍可以组成退化的三角形,输出 SEGMENT;否则,输出 IMPOSSIBLE

By @PC_DOS

题目描述

Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.

The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.

输入格式

The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks.

输出格式

Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.

样例 #1

样例输入 #1

4 2 1 3

样例输出 #1

TRIANGLE

样例 #2

样例输入 #2

7 2 2 4

样例输出 #2

SEGMENT

样例 #3

样例输入 #3

3 5 9 1

样例输出 #3

IMPOSSIBLE

代码如下:

#include<string.h>
#include<stdio.h>
#include<math.h>
#include <stdlib.h>int S(int a ,int b,int c){if(a + b> c&&b + c > a&&a + c > b){return 2;}else if(a + b>= c&&b + c >= a&&a + c >= b){return 1;}else {return 0;}
}int main()
{int a, b, c, d;scanf("%d%d%d%d",&a,&b,&c,&d);int num1,num2,num3,num4;num1 = S(a, b, c);num2 = S(a, b, d);num3 = S(a, c, d);num4 =S(b, c, d);if(num1 == 2||num2 == 2||num3 == 2||num4 == 2){printf("TRIANGLE\n");}else if(num1 == 1||num2 == 1||num3 == 1||num4 == 1){printf("SEGMENT\n");}else {printf("IMPOSSIBLE\n");}return 0;
}

五、Die Roll

题面翻译

小Y,小W和小D进行扔骰子(六面)游戏,谁投出的点数最大算谁胜利,现在已知小Y和小W的得分,请你帮小D求出她获胜的概率

注意:

1.以"分子/分母"输出,特别的,若不可能获胜输出"0/1",100%获胜输出"1/1"

2.小Y和小W非常绅士,如果小D的得分和他们一样,他们也会算作小D获胜
Translated by @稀神探女

题目描述

Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.

But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That’s why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.

Yakko thrown a die and got Y points, Wakko — W points. It was Dot’s turn. But she didn’t hurry. Dot wanted to know for sure what were her chances to visit Transylvania.

It is known that Yakko and Wakko are true gentlemen, that’s why if they have the same amount of points with Dot, they will let Dot win.

输入格式

The only line of the input file contains two natural numbers Y and W — the results of Yakko’s and Wakko’s die rolls.

输出格式

Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».

样例 #1

样例输入 #1

4 2

样例输出 #1

1/2

提示

Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.

代码如下:

#include<string.h>
#include<stdio.h>
#include<math.h>
#include <stdlib.h>int main()
{int a, b;scanf("%d%d",&a,&b);int max = a;if(a < b){max = b;}int x = 7 - max;int y = 6;if(x%2 == 0){x = x/2;y = y/2;}if(x%3 == 0){x = x/3;y = y/3;}printf("%d/%d",x,y);return 0;
}

CodeForces刷题:Theatre Square、Watermelon、Chat Server‘s Outgoing Traffic、Triangle、Die Roll相关推荐

  1. CF5A Chat Server's Outgoing Traffic(字符串模拟,find函数的应用)难度⭐

    题意翻译 Polycarp正在开发一个名为"Polychat"的新项目.按照IT的现代倾向,他决定,这个项目也应该包含聊天.为了实现这一目标,Polycarp在笔记本电脑前花费了几 ...

  2. 【Python爬虫实战】codeforces刷题记录小助手

    先看效果图. 输入codeforces的用户名,可以查询用户的rating信息.以及参加比赛的信息(大星参数的不计算在内).还有总的AC数. 一.需求分析 找到显示用户参加contest信息的url. ...

  3. 【CodeForces - 1A】Theatre Square(水题,几何)(CODEFORCES,梦的开始)

    题干: Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters ...

  4. Codeforces 刷题记录(已停更)

    Codeforces 每日刷题记录 (已停更) 打'+'是一些有启发意义的题目,部分附上一句话题解,每日更新3题,大部分题目较水. Day ID Problem Tutorial Note 1 1 + ...

  5. CodeForces刷题C语言:What is for dinner?、Reconnaissance 2、Shell Game、Extra-terrestrial Intelligence、Extra

    记录洛谷刷题c语言QAQ 一.What is for dinner? 题面翻译 题面描述 鲨鱼有 n n n 颗牙齿,分别分布于 m m m 行上,第 i i i 颗牙齿有一个初始活力值 c i c_ ...

  6. CodeForces刷题C语言:Next Test、Spit Problem、Traffic Lights、Reconnaissance、Borze

    记录洛谷刷题C语言 一.Next Test 题面翻译 题面描述 给出 nnn 个互不相同的整数 aia_iai​ ,从小到大找第一个没有出现过的整数. 输入格式 第一行一个正整数 nnn ,之后是 n ...

  7. 【11.9】Codeforces 刷题

    DP\text{DP}DP : B. Yaroslav and Two Strings 题意: 如果两个只包含数字且长度为 n(1≤n≤105)n(1\leq n\leq 10^5)n(1≤n≤105 ...

  8. Codeforces刷题

    Codeforces100套刷题 Codeforces Round #506 (Div. 3) Educational Codeforces Round 49 (Rated for Div. 2) A ...

  9. 【4.29】Codeforces 刷题

    C1. Pokémon Army (easy version) 题意:给出一个序列 aaa ,要求求出一个单调递增的下标序列 bbb ,使得 ans=ab1−ab2+ab3−ab4+...ans=a_ ...

最新文章

  1. input change获取改变之前的值和改变之后的值_使用Vue3.0新特性造轮子 WidgetUI3.0 (Input输入框组件)
  2. 大数高精运算-----乘法
  3. 面试官:看你简历写了熟悉Kafka,它为什么速度会这么快?
  4. 【阿里妈妈数据科学系列】第二篇:在线分流框架下的AB Test
  5. ASP.NET Core2读写InfluxDB时序数据库
  6. 第十五期:真相了,中台到底“出路”还是“末路”?
  7. Bootstrap系列 -- 23. 图片
  8. Python全栈开发——面向对象的三大特性(继承 多态 封装)
  9. 在IDEA中右键New没有创建Mapper文件选项解决办法
  10. phpcmsV9怎样在单页中调用后台栏目SEO设置的Meta_title
  11. phpfpm怎么连接mysql_php-fpm连不上mysql的问题?
  12. Zookeeper Tutorial 2 -- Programmer's Guide
  13. Java的equals()和==的区别
  14. java 网络实验_java网络聊天室实验
  15. Linux操作系统使用基础06:文件与文件系统的压缩与打包
  16. linux scp 隐藏文件,scp 客户端发现了隐藏 35 年的漏洞
  17. bag of word C++图像批量读写
  18. bzoj4332;vijos1955:JSOI2012 分零食
  19. linux下 使用apache2 ab 测试进行压力测试
  20. 2022尚硅谷docker学习笔记

热门文章

  1. Python DiffLib -- 文本内容对比
  2. EasyExcel写入excel模板
  3. 端口扫描程序 快速扫描 多线程、范围端口、范围IP、查看历史记录 Windows/MacOS
  4. 修改taro-ui的样式,在自定义组件中使用taro-ui,修改ui框架样式
  5. 常见的系统设计问题以及思路
  6. MySQL 中直接生成数据字典方法(需在设计时为表、字段写好备注)
  7. VB作业之字母大小写的转换
  8. TestNG框架的环境搭建
  9. mpeg2-ts格式解析
  10. 黑鹰VB,黑基破解,黑鹰 ASP,华夏脚本,华夏破解黑鹰VB编程教程