记录洛谷刷题c语言QAQ


一、What is for dinner?

题面翻译

题面描述

鲨鱼有 n n n 颗牙齿,分别分布于 m m m 行上,第 i i i 颗牙齿有一个初始活力值 c i c_i ci​。鲨鱼有 k k k 个食物想要吃,但是,每吃掉一个食物就要消耗某一排牙齿的每一颗牙齿各 1 1 1 点活力,而鲨鱼必须保证每个牙齿的剩余活力不能到负数。 试求鲨鱼最多能吃到的食物个数。

输入格式

第一排三个整数 n , m , k n,m,k n,m,k,后面 n n n 排每行两个整数 x x x 和 c i c_i ci​,分别表示这个牙齿所在的行数和初始活力值。

输出格式

输出一个整数,为答案。

数据范围与约定

  • 1 ≤ m ≤ n ≤ 1000 1 \leq m \leq n \leq 1000 1≤m≤n≤1000;
  • 0 ≤ k ≤ 1 0 6 0 \leq k \leq 10^6 0≤k≤106;
  • 1 ≤ x ≤ m 1 \leq x \leq m 1≤x≤m;
  • 0 ≤ c i ≤ 1 0 6 0 \leq c_i \leq 10^6 0≤ci​≤106。

题目描述

In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie’s distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are “relaxing”.

For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie’s developing caries (for what he was later nicknamed Cap).

It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie’s tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again.

Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn’t say no to her favourite meal, but she had no desire to go back to the dentist. That’s why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative.

As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner.

We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one.

输入格式

The first line contains three integers $ n $ , $ m $ , $ k $ ( $ 1<=m<=n<=1000,0<=k<=10^{6} $ ) — total amount of Valerie’s teeth, amount of tooth rows and amount of crucians in Valerie’s portion for dinner. Then follow $ n $ lines, each containing two integers: $ r $ ( $ 1<=r<=m $ ) — index of the row, where belongs the corresponding tooth, and $ c $ ( $ 0<=c<=10^{6} $ ) — its residual viability.

It’s guaranteed that each tooth row has positive amount of teeth.

输出格式

In the first line output the maximum amount of crucians that Valerie can consume for dinner.

样例 #1

样例输入 #1

4 3 18
2 3
1 2
3 6
2 3

样例输出 #1

11

样例 #2

样例输入 #2

2 2 13
1 13
2 12

样例输出 #2

13

代码如下:

#include<string.h>
#include<stdio.h>
#include<math.h>
#include <stdlib.h>int main()
{int n, m, k;scanf("%d%d%d",&n,&m,&k);int len[m+1];for(int i = 1;i <= m;i++){len[i] = 10000001;} for(int i = 1;i <= n;i++){int x, y;scanf("%d%d",&x,&y);if(y <= len[x]){len[x] = y;}}int sum = 0;for(int i = 1;i <= m;i++){if(len[i] != 10000001){sum = sum + len[i];} }if(sum >= k){printf("%d\n",k);}else{printf("%d\n",sum);}return 0;
}

二、Reconnaissance 2

题面翻译

题目描述:操场上有n个士兵站成了一个环,每名士兵有一个身高h[i],试求两相邻士兵x,y,使得士兵x和士兵y身高差最小。

输入:第一行n,之后n个整数h[i];

输出:题目描述中的x,y,若有多解任意输出一组即可。

2<=n<=100,1<=ai<=1000

Translated by @稀神探女

题目描述

$ n $ soldiers stand in a circle. For each soldier his height $ a_{i} $ is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. $ |a_{i}-a_{j}| $ is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.

输入格式

The first line contains integer $ n $ ( $ 2<=n<=100 $ ) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — $ n $ space-separated integers $ a_{1},a_{2},…,a_{n} $ ( $ 1<=a_{i}<=1000 $ ). The soldier heights are given in clockwise or counterclockwise direction.

输出格式

Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.

样例 #1

样例输入 #1

5
10 12 13 15 10

样例输出 #1

5 1

样例 #2

样例输入 #2

4
10 20 30 40

样例输出 #2

1 2

提示

题目描述:

操场上有 n n n 个士兵站成了一个环,每名士兵有一个身高 h i h_i hi​,试求两相邻士兵 x , y x,y x,y,使得士兵 x x x 和士兵 y y y 身高差最小。

输入:

第一行 n n n,之后 n n n 个整数 h i h_i hi​。

输出:

题目描述中的 x , y x,y x,y,若有多解任意输出一组即可。

数据范围:

2 ≤ n ≤ 100 , 1 ≤ h i ≤ 1000 2\leq n\leq100,1\leq h_i\leq1000 2≤n≤100,1≤hi​≤1000

Translated by @稀神探女,Reformed by @chenyilai。

代码如下:

#include<string.h>
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
int n,m=1001,x,y;
int a[105];
int i,j,k;
int main(){scanf("%d",&n);for(i=1;i<=n;i++){scanf("%d",&a[i]);}for(i=0;i<n;i++){if(m>abs(a[i%n+1]-a[(i+1)%n+1])){m=abs(a[i%n+1]-a[(i+1)%n+1]);x=i%n+1;y=(i+1)%n+1;}}printf("%d %d\n",x,y);return 0;
}

二、Shell Game

题面翻译

题目描述

经典的转纸杯游戏。给定小球初始所在的纸杯位置和 3 3 3 次交换纸杯的操作,问你最后小球的位置。

输入格式

第一行一个整数。标识小球的初始位置,之后 3 3 3 行每行两个整数 a , b a,b a,b 表示交换 a , b a,b a,b 纸杯。(要注意的是:最左边的杯子编号永远为 1 1 1,最右边的编号永远为 3 3 3,不会随着交换而改变)

输出格式

一个整数,表示最后小球所在的纸杯编号。

本题目中所有数字均不超过 3 3 3。

题目描述

Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too?

输入格式

The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3.

输出格式

In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles.

样例 #1

样例输入 #1

1
1 2
2 1
2 1

样例输出 #1

2

样例 #2

样例输入 #2

1
2 1
3 1
1 3

样例输出 #2

2

代码如下:

#include<string.h>
#include<stdio.h>
#include<math.h>
#include <stdlib.h>int n,a,b,ans;
int main(){scanf("%d",&n);ans = n;for(int i = 0;i < 3;++i){scanf("%d%d",&a,&b);if(a==ans)  ans=b;else if(b==ans) ans=a;}printf("%d\n",ans);return 0;
}

四、Extra-terrestrial Intelligence

题目背景

注意这题要加上这个:

freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);

题面翻译

给定一 01 01 01 序列,试问其中的 1 1 1 是否等距.若等距则输出YES,否则输出NO
Translated by @稀神探女

input: input.txt

output: output.txt

题目描述

Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for $ n $ days in a row. Each of those $ n $ days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that he has found extra-terrestrial intelligence if there is a system in the way the signals has been received, i.e. if all the intervals between successive signals are equal. Otherwise, Vasya thinks that the signals were sent by some stupid aliens no one cares about. Help Vasya to deduce from the information given by the receiver if he has found extra-terrestrial intelligence or not.

输入格式

The first line contains integer $ n $ ( $ 3<=n<=100 $ ) — amount of days during which Vasya checked if there were any signals. The second line contains $ n $ characters 1 or 0 — the record Vasya kept each of those $ n $ days. It’s guaranteed that the given record sequence contains at least three 1s.

输出格式

If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO.

样例 #1

样例输入 #1

8
00111000

样例输出 #1

YES

样例 #2

样例输入 #2

7
1001011

样例输出 #2

NO

样例 #3

样例输入 #3

7
1010100

样例输出 #3

YES

代码如下:

#include<string.h>
#include<stdio.h>
#include<math.h>
#include <stdlib.h>int n,a[105],l1,l2;
int main(void){freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);scanf ("%d",&n);for (int i=1;i<=n;i++){scanf("%1d",&a[i]);if(a[i]&&!l1)l1=i;//记录第一个1else if (a[i]&&!l2)l2=i;//记录第2个1}for (int i=l2+1;i<=n;i++)if (a[i]&&i-l2==l2-l1)l1=l2,l2=i;//间隔相同,更新else if(a[i])return !printf ("NO");//不相同直接退出printf ("YES");
}

五、Towers

题面翻译

题面描述

Little Vasya 收到了一个来自青年建筑师的盒子,盒子里有 n n n( 1 ≤ n ≤ 1000 1 \leq n \leq 1000 1≤n≤1000)条木头。现在他知道每条木头的长度,如果有两根木头长度一致,则他可以把其中一条放在另一条的顶部。

Vasya 想知道用木头建立的塔的最小数量。帮助 Vasya 以最好的方式使用这些木头(每根木头都要用上)。

输入格式

第一行: n n n。

第二行:每条木头的长度(小于 1000 1000 1000 的自然数)。

输出格式

最大塔的高度(某塔叠放木头数量)及其塔的总数。记住,Vasya 应该利用所有的木头。

题目描述

Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.

Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.

输入格式

The first line contains an integer $ N $ ( $ 1<=N<=1000 $ ) — the number of bars at Vasya’s disposal. The second line contains $ N $ space-separated integers $ l_{i} $ — the lengths of the bars. All the lengths are natural numbers not exceeding $ 1000 $ .

输出格式

In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.

样例 #1

样例输入 #1

3
1 2 3

样例输出 #1

1 3

样例 #2

样例输入 #2

4
6 5 6 7

样例输出 #2

2 3

代码如下:

#include<string.h>
#include<stdio.h>
#include<math.h>
#include <stdlib.h>int a[1010];//开一个桶
int main(){int n,i,s=0,x,m=0;scanf("%d",&n);for(i = 0;i < n;i++){scanf("%d",&x);a[x]++;//将对应桶的数量增加。}for(i = 0;i <= 1000;i++){if(a[i])m++;//找有的长度。if(a[i]>s)s=a[i];//找最多数量。}printf("%d %d\n",s,m);
}

CodeForces刷题C语言:What is for dinner?、Reconnaissance 2、Shell Game、Extra-terrestrial Intelligence、Extra相关推荐

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

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

  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. 十进制转十六进制(蓝桥杯)
  2. htop 比top更好用的top
  3. 点权生成树(gentree)
  4. Linux之Server环境配置
  5. U92904-画地为佬【二分,结论】
  6. oracle优质图书,经典Oracle图书推荐(之四)_oracle
  7. VC 位图按钮CBitmapButton的使用
  8. [转]UINavigationController的用法详解
  9. php 导航栏链接网页,怎样用php来给网页做导航栏_php实例
  10. 数据结构与算法分析-用C语言实现栈(数组方式)
  11. 前端vue项目开发流程
  12. 基于微信小程序的考勤打卡系统
  13. java B2B2C Springcloud电子商城系统- Gateway初体验
  14. Holo 使用场景说明
  15. GitHub项目徽章的添加和设置
  16. 邮件服务器公网IP被国外反垃圾联盟(PBL)列入黑名单移除操作方法
  17. nginx 客户端返回499的错误码
  18. Ansible Inventory详细使用介绍
  19. 抑郁症自我测试皮肤软件,以躯体症状为主的抑郁症患者的交感神经皮肤反应研究...
  20. win10解决桌面图标变白

热门文章

  1. unity 手指控制UI移动和放大缩小
  2. php 大转盘 抽奖概率算法
  3. java时间比较方法
  4. 计算机硬件英汉对照表
  5. 艺术核心素养如何在课程中实现
  6. 《面试八股文》之Dubbo17卷
  7. 常见SQL语句的加锁分析
  8. boostrap的应用
  9. P value校正思想与实现
  10. 数据库 事务级别介绍