记录洛谷刷题C语言


一、Next Test

题面翻译

题面描述

给出 nnn 个互不相同的整数 aia_iai​ ,从小到大找第一个没有出现过的整数。

输入格式

第一行一个正整数 nnn ,之后是 nnn 个整数 aia_iai​ 。

输出格式

一个整数 xxx ,即第一个没有出现过的整数。

数据范围与约定

1≤n≤30001\leq n\leq 30001≤n≤3000

1≤ai≤30001\leq a_i\leq 30001≤ai​≤3000

题目描述

«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.

You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.

输入格式

The first line contains one integer $ n $ ( $ 1<=n<=3000 $ ) — the amount of previously added tests. The second line contains $ n $ distinct integers $ a_{1},a_{2},…,a_{n} $ ( $ 1<=a_{i}<=3000 $ ) — indexes of these tests.

输出格式

Output the required default value for the next test index.

样例 #1

样例输入 #1

3
1 7 2

样例输出 #1

3

代码如下:

#include<string.h>
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
int num[300001];
int main()
{int n;scanf("%d",&n);
//  for(int i = 1;i <= 3000;i++)
//  {//      num[i] = 0;
//  }for(int i = 0;i < n;i++){int m;scanf("%d",&m);num[m] = 1;}for(int i = 1;i <= 300001;i++){if(num[i] != 1){printf("%d\n",i);break;}}return 0;
}

二、Spit Problem

题面翻译

在一条数轴上有 nnn 个点,每个点都有位置 xix_ixi​ 和系数 did_idi​,求有没有两个点的编号 i,ji,ji,j(i≠ji\neq ji=j)使得 xi+di=xjx_i+d_i=x_jxi​+di​=xj​ 而且 xj+dj=xix_j+d_j=x_ixj​+dj​=xi​ 。

题目描述

In a Berland’s zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task.

The trajectory of a camel’s spit is an arc, i.e. if the camel in position $ x $ spits $ d $ meters right, he can hit only the camel in position $ x+d $ , if such a camel exists.

输入格式

The first line contains integer $ n $ ( $ 1<=n<=100 $ ) — the amount of camels in the zoo. Each of the following $ n $ lines contains two integers $ x_{i} $ and $ d_{i} $ ( $ -10{4}<=x_{i}<=10{4},1<=|d_{i}|<=2·10^{4} $ ) — records in Bob’s notepad. $ x_{i} $ is a position of the $ i $ -th camel, and $ d_{i} $ is a distance at which the $ i $ -th camel spitted. Positive values of $ d_{i} $ correspond to the spits right, negative values correspond to the spits left. No two camels may stand in the same position.

输出格式

If there are two camels, which spitted at each other, output YES. Otherwise, output NO.

样例 #1

样例输入 #1

2
0 1
1 -1

样例输出 #1

YES

样例 #2

样例输入 #2

3
0 1
1 1
2 -2

样例输出 #2

NO

样例 #3

样例输入 #3

5
2 -10
3 10
0 5
5 -5
10 1

样例输出 #3

YES

代码如下:

#include<string.h>
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
int a[10000],x[10000];//定义两个数组
int main()
{int n;scanf("%d",&n);for(int i=1; i<=n; i++){scanf("%d%d",&a[i],&x[i]);}for(int i=1; i<=n; i++)//暴力枚举{for(int j=1; j<=n; j++)if(i!=j)//如果他们两不是同一只骆驼{if(a[i]+x[i]==a[j]&&a[j]+x[j]==a[i])//如果他们可以互相吐口水{printf("YES\n");return 0;//可以直接结束程序}}}printf("NO\n");return 0;
}

三、Traffic Lights

题面翻译

题目描述

一辆汽车以vvv 米每秒的速度由A点驶向B点。这个动作发生在X轴上。在距离A点ddd 米的地方有一个红绿灯。从0时刻开始,在第一个ggg 秒里绿灯是亮的,然后在接下来的rrr 秒内红灯亮起,在接下来ggg 秒,绿灯亮起,如此反复。

这辆车可以瞬间从000 加速到vvv ,反之亦然,也可以从vvv 瞬间减速至000 。车在绿灯时可以立刻通过。如果车在红灯亮起的那一刻到达红绿灯处,那么车不能够通过。但如果在绿灯亮起时到达,则可以通过。车从0时刻离开A点。

在不违反交通规则的前提下,车从A点移动到B点最少需要多长时间?

输入格式:

第一行包含整数l,d,v,g,rl,d,v,g,rl,d,v,g,r (1≤l,d,v,g,r≤1000,d<l1\leq l,d,v,g,r\leq1000,d<l1≤l,d,v,g,r≤1000,d<l )— A与B间的距离(米),A与红绿灯的距离,车的速度,绿灯的持续时间和红灯的持续时间。

输出格式:

输出一个数 — 车从A到B所需要的最少时间。你的输出需要和标准输出相差不超过10−610^{-6}10−6

Translated by Khassar

题目描述

A car moves from point A to point B at speed $ v $ meters per second. The action takes place on the X-axis. At the distance $ d $ meters from A there are traffic lights. Starting from time 0, for the first $ g $ seconds the green light is on, then for the following $ r $ seconds the red light is on, then again the green light is on for the $ g $ seconds, and so on.

The car can be instantly accelerated from $ 0 $ to $ v $ and vice versa, can instantly slow down from the $ v $ to $ 0 $ . Consider that it passes the traffic lights at the green light instantly. If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn’t have time to pass it. But if it approaches the traffic lights at the moment when the green light has just turned on, it can move. The car leaves point A at the time 0.

What is the minimum time for the car to get from point A to point B without breaking the traffic rules?

输入格式

The first line contains integers $ l $ , $ d $ , $ v $ , $ g $ , $ r $ ( $ 1<=l,d,v,g,r<=1000,d<l $ ) — the distance between A and B (in meters), the distance from A to the traffic lights, car’s speed, the duration of green light and the duration of red light.

输出格式

Output a single number — the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than $ 10^{-6} $ .

样例 #1

样例输入 #1

2 1 3 4 5

样例输出 #1

0.66666667

样例 #2

样例输入 #2

5 4 3 1 1

样例输出 #2

2.33333333

代码如下:

double ans;
int main(){double l,d,v,g,r;scanf("%lf%lf%lf%lf%lf",&l,&d,&v,&g,&r);if(l<=d)ans=l/v;else{double t=d/v;while(t>=g+r)t-=g+r;if(t<g)ans=l/v;else ans=g+r-t+l/v;}printf("%.8lf",ans);
}

四、Reconnaissance

题面翻译

题目描述

根据Berland军队的规定,一个巡逻队应当包含两名士兵。由于这两名士兵不能相差太多,它们的身高相差不能超过ddd 厘米。Bob上尉有nnn 名士兵在他的支队中。他们的身高分别是a1,a2,…,ana_1,a_2,\ldots,a_na1​,a2​,…,an​ 厘米。一些士兵有着相同的身高。Bob想知道他有多少种能从他的支队中选拔一个巡逻队出来的方案。

方案(1,2)(1,2)(1,2) 和(2,1)(2,1)(2,1) 应当被视作是不同的

输入格式:

第一行两个整数nnn 和ddd (1≤n≤1000,1≤d≤1091\leq n\leq1000,1\leq d\leq10^91≤n≤1000,1≤d≤109 )— Bob的支队中的士兵的数量和最大所被允许的身高差距。第二行包含个空格分开的整数 — Bob支队中所有士兵的身高。这些数不会超过10910^9109

输出格式:

输出一个数 — 高度差不超过ddd 的士兵组成巡逻队的方案数

Translated by Khassar

题目描述

According to the regulations of Berland’s army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn’t differ much, their heights can differ by at most $ d $ centimeters. Captain Bob has $ n $ soldiers in his detachment. Their heights are $ a_{1},a_{2},…,a_{n} $ centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.

Ways $ (1,2) $ and $ (2,1) $ should be regarded as different.

输入格式

The first line contains two integers $ n $ and $ d $ ( $ 1<=n<=1000,1<=d<=10^{9} $ ) — amount of soldiers in Bob’s detachment and the maximum allowed height difference respectively. The second line contains $ n $ space-separated integers — heights of all the soldiers in Bob’s detachment. These numbers don’t exceed $ 10^{9} $ .

输出格式

Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn’t exceed $ d $ .

样例 #1

样例输入 #1

5 10
10 20 50 60 65

样例输出 #1

6

样例 #2

样例输入 #2

5 1
55 30 29 31 55

样例输出 #2

6

代码如下:

#include<string.h>
#include<stdio.h>
#include<math.h>
#include <stdlib.h>int a[1001],n,d,ans;//按题意变量开这么大就够了
int main(){scanf("%d%d",&n,&d);//个人建议用scanf和printf比较好for(int i=1;i<=n;i++) scanf("%d",&a[i]);for(int i=2;i<=n;i++)           for(int j=1;j<i;j++) //遍历,加入简单的剪枝if(a[i]-a[j]<=d&&a[i]-a[j]>=-d) ans+=2;//如果身高差小于d就满足,而且一次加2,省时间printf("%d\n",ans);//换行,好习惯return 0;
}

五、Borze

题面翻译

题面描述

三进制数字符号在Berland很受欢迎。如果用borze编码表示电报的三进制数。数字 0,1,20,1,20,1,2 分别被作为.-.--。你需要为borze编码解码。(把borze编码转换为三进制数)。

输入格式

第一行包含在Borze编码。字符串的长度介于 111 到 200200200 个字符之间。这是保证给定的字符串是一个有效的一些三元数borze编码(这个数可能有前导零)。

输出格式

一个三进制数(如果有前导零要输出)。

题目描述

Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «–». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.

输入格式

The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It’s guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).

输出格式

Output the decoded ternary number. It can have leading zeroes.

样例 #1

样例输入 #1

.-.--

样例输出 #1

012

样例 #2

样例输入 #2

--.

样例输出 #2

20

样例 #3

样例输入 #3

-..-.--

样例输出 #3

1012

代码如下:

#include<string.h>
#include<stdio.h>
#include<math.h>
#include <stdlib.h>char s[1000];
int main()
{scanf("%s",&s);int len=strlen(s);//测算长度for(int i=0;i<len;++i)//循环判断{if(s[i]=='.')//“.”是0,此时不用重置(想一想,为什么)printf("0");if(s[i]=='-')//一条横分类讨论{if(s[i+1]=='.')//“-.”为1printf("1");if(s[i+1]=='-')//“--”为2printf("2");s[i+1]='?';//快乐重置}}return 0;
}

CodeForces刷题C语言:Next Test、Spit Problem、Traffic Lights、Reconnaissance、Borze相关推荐

  1. 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_ ...

  2. 洛谷刷题C语言:潇湘の雨、分糖果、Addition、Ljeto、TRI

    记录洛谷刷题C语言QAQ 「PMOI-0」潇湘の雨 题目背景 (原 LZOI-1,改名已经 PMOI 成员同意) lhm-01 题目描述 言琢დ 在一个 2n×2n2n \times 2n2n×2n ...

  3. 洛谷刷题C语言:Bold、饱食、公平の意、DOM、

    记录洛谷刷题C语言qaq [COCI2020-2021#6] Bold 题目描述 Paula 给 Daniel 写了一封信,她需要加粗文本的字体,以便视力恶化的 Daniel 阅读. 信可以用 . 和 ...

  4. 洛谷刷题C语言:陶瓷项链、Cow Gymnastics B、Where Am I? B、Hello, 2020!、SIR 模型

    记录洛谷刷题C语言 一.[NOI2000] 瓷片项链 题目描述 原始部落用一种稀有的泥土烧制直径相同的圆瓷片并串成项链,串的时候沿瓷片的直径方向顺次连接,瓷片之间没有空隙也不重叠,一条项链至少由一个瓷 ...

  5. CodeForces刷题:Theatre Square、Watermelon、Chat Server‘s Outgoing Traffic、Triangle、Die Roll

    记录Codeforces刷题QAQ 一.Theatre Square 题面翻译 用 $ a \times a$ 的石板覆盖 $n \times m $ 的长方形广场,允许石板覆盖的区域超出广场,不允许 ...

  6. 洛谷刷题C语言:切蛋糕、概率、Bridž、NOTE、DOMINO

    记录洛谷刷题C语言qaq [NOI Online 2021 入门组] 切蛋糕 题目描述 Alice.Bob 和 Cindy 三个好朋友得到了一个圆形蛋糕,他们打算分享这个蛋糕. 三个人的需求量分别为 ...

  7. 洛谷刷题C语言:Physics Problem、PARKING、Trol、信息学竞赛、POT

    记录洛谷刷题C语言 「dWoi R1」Physics Problem 题目背景 面对白板上的物理题,王马陷入了沉思 -- 题目描述 有 nnn 个状态,编号为 111 到 nnn.这 nnn 个状态之 ...

  8. 洛谷刷题C语言:Fergusonball Ratings、Don‘t Mozheng. /oh、gcd.、幻想乡扑克游戏、PMTD

    记录洛谷刷题C语言qaq [CCC2022 J2] Fergusonball Ratings 题目描述 现在有一个球队需要你评价. 球队中的第 i i i 个人进了 a i a_i ai​ 个球,犯规 ...

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

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

最新文章

  1. oracle账户锁定解决方法
  2. 如何轻松搞定CRUD的创建人、修改人、时间等字段的赋值
  3. 动态生成一个继承接口的类
  4. 简单的Ajax应用实例
  5. PHP中数组的三种排序方法
  6. mac屏幕截图_如何在Mac上拍摄屏幕截图
  7. Linux挂载命令mount详解
  8. 转:绝对干货--WordPress自定义查询wp_query所有参数详细注释
  9. 黄学长模拟day1 球的序列
  10. 诗与远方:无题(三十二)- 曾经写给妹子的一首诗
  11. 温度传感器硬件编号_打开硬件传感器BITalino进行酷项目
  12. Python的条件判断与循环样例
  13. AtCoder Grand Contest 023
  14. 数据分页模块系列 (二) 完美封装PageModel实现分页模块
  15. Abaqus 子结构分析 实例
  16. NCU SEM 发文检索2015年
  17. 体系结构:Cache Coherence
  18. BD-rate计算方法
  19. matplotlib(直方图,条形图,饼图,散点图)基础知识
  20. 开源mysql web平台_Yearning Mysql–Web端SQL审核平台

热门文章

  1. 春节没有年味?今年就去这些年味浓的地方过年吧!
  2. 穷人冲冲冲:为什么总是“坏人”赚钱?
  3. uniapp图片编辑器,支持自定义尺寸、缩放、拖动、裁剪
  4. C# 给PDF签名时添加时间戳的2种方法)
  5. jmap分析工具class name
  6. 无穷级数 | 抽象的数列级数及例题
  7. 互联网产品设计师如何设计推出一款新的产品
  8. 网站建设过程中流行的50种字体
  9. 教你如何搭建培训机构-招生管理系统,demo可分享
  10. java开发地三天——数据库介绍