记录洛谷刷题C语言
给出 n n n 个互不相同的整数 a i a_i ai ,从小到大找第一个没有出现过的整数。
第一行一个正整数 n n n ,之后是 n n n 个整数 a i a_i ai 。
一个整数 x x x ,即第一个没有出现过的整数。
1 ≤ n ≤ 3000 1\leq n\leq 3000 1≤n≤3000
1 ≤ a i ≤ 3000 1\leq a_i\leq 3000 1≤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.
3
1 7 2
3
#include
#include
#include
#include
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;
}
在一条数轴上有 n n n 个点,每个点都有位置 x i x_i xi 和系数 d i d_i di,求有没有两个点的编号 i , j i,j i,j( i ≠ j i\neq j i=j)使得 x i + d i = x j x_i+d_i=x_j xi+di=xj 而且 x j + d j = x i x_j+d_j=x_i xj+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.
2
0 1
1 -1
YES
3
0 1
1 1
2 -2
NO
5
2 -10
3 10
0 5
5 -5
10 1
YES
#include
#include
#include
#include
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;
}
一辆汽车以 v v v 米每秒的速度由A点驶向B点。这个动作发生在X轴上。在距离A点 d d d 米的地方有一个红绿灯。从0时刻开始,在第一个 g g g 秒里绿灯是亮的,然后在接下来的 r r r 秒内红灯亮起,在接下来 g g g 秒,绿灯亮起,如此反复。
这辆车可以瞬间从 0 0 0 加速到 v v v ,反之亦然,也可以从 v v v 瞬间减速至 0 0 0 。车在绿灯时可以立刻通过。如果车在红灯亮起的那一刻到达红绿灯处,那么车不能够通过。但如果在绿灯亮起时到达,则可以通过。车从0时刻离开A点。
在不违反交通规则的前提下,车从A点移动到B点最少需要多长时间?
第一行包含整数
l
,
d
,
v
,
g
,
r
l,d,v,g,r
l,d,v,g,r (
1
≤
l
,
d
,
v
,
g
,
r
≤
1000
,
d
<
l
1\leq l,d,v,g,r\leq1000,d
输出格式:
输出一个数 — 车从A到B所需要的最少时间。你的输出需要和标准输出相差不超过 1 0 − 6 10^{-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 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} $ . 根据Berland军队的规定,一个巡逻队应当包含两名士兵。由于这两名士兵不能相差太多,它们的身高相差不能超过
d
d
d 厘米。Bob上尉有
n
n
n 名士兵在他的支队中。他们的身高分别是
a
1
,
a
2
,
…
,
a
n
a_1,a_2,\ldots,a_n
a1,a2,…,an 厘米。一些士兵有着相同的身高。Bob想知道他有多少种能从他的支队中选拔一个巡逻队出来的方案。 方案
(
1
,
2
)
(1,2)
(1,2) 和
(
2
,
1
)
(2,1)
(2,1) 应当被视作是不同的 第一行两个整数
n
n
n 和
d
d
d (
1
≤
n
≤
1000
,
1
≤
d
≤
1
0
9
1\leq n\leq1000,1\leq d\leq10^9
1≤n≤1000,1≤d≤109 )— Bob的支队中的士兵的数量和最大所被允许的身高差距。第二行包含个空格分开的整数 — Bob支队中所有士兵的身高。这些数不会超过
1
0
9
10^9
109 输出一个数 — 高度差不超过
d
d
d 的士兵组成巡逻队的方案数 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 $ . 三进制数字符号在Berland很受欢迎。如果用borze编码表示电报的三进制数。数字
0
,
1
,
2
0,1,2
0,1,2 分别被作为 第一行包含在Borze编码。字符串的长度介于
1
1
1 到
200
200
200 个字符之间。这是保证给定的字符串是一个有效的一些三元数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
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
题面翻译
题目描述
输入格式:
输出格式:
题目描述
输入格式
输出格式
样例 #1
样例输入 #1
5 10
10 20 50 60 65
样例输出 #1
6
样例 #2
样例输入 #2
5 1
55 30 29 31 55
样例输出 #2
6
代码如下:
#include
五、Borze
题面翻译
题面描述
.
,-.
和--
。你需要为borze编码解码。(把borze编码转换为三进制数)。输入格式
输出格式
题目描述
输入格式
输出格式
样例 #1
样例输入 #1
.-.--
样例输出 #1
012
样例 #2
样例输入 #2
--.
样例输出 #2
20
样例 #3
样例输入 #3
-..-.--
样例输出 #3
1012
代码如下:
#include