From 40c57a83df2a95bfed59d94c67ab64f7837ac4b8 Mon Sep 17 00:00:00 2001
From: qq_44193969 <2608882093@qq.com>
Date: Fri, 24 Dec 2021 16:31:41 +0800
Subject: [PATCH] add 3 exercises
---
.../1.cpp/1.exercises/solution.md" | 77 +++++--
.../1.cpp/2.exercises/solution.md" | 104 ++++++---
.../1.cpp/3.exercises/solution.md" | 198 ++++++++++++++----
3 files changed, 287 insertions(+), 92 deletions(-)
diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/1.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/1.exercises/solution.md"
index ede205c47..8347615fe 100644
--- "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/1.exercises/solution.md"
+++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/1.exercises/solution.md"
@@ -11,33 +11,62 @@
样例输出
2 200
提示
【样例解释】
乐乐咨询了 3 个商家,打算购买一二三等奖奖品数量分别是 1 个、2 个、3 个,编号为 1 的商家一二三等奖奖品报价分别是 70、50、30 元,编号为 2 的商家报价分别是 60、40、20 元,编号为 3 的商家报价分别是 80、55、20 元,乐乐在编号为 2 的商家购买总费用最低,为200 元。
【数据范围】
40%数据:1≤n≤5000
100%数据:1≤n≤100000,1≤x,y,z≤1000,奖品报价都是 1000 范围以内的正整数。
+以下程序实现了这一功能,请你填补空白处的内容:
+
+```cpp
+#include
+#include
+using namespace std;
+int main()
+{
+ int n, x, y, z, i, min = 1000000, n1, n2, n3, temp, t = 0;
+ cin >> n >> x >> y >> z;
+ for (i = 0; i < n; i++)
+ {
+ temp = 0;
+ cin >> n1 >> n2 >> n3;
+ temp += n1 * x + n2 * y + n3 * z;
+ __________________
+ }
+ cout << t << " " << min;
+ return 0;
+}
+```
+
## template
```cpp
#include
#include
using namespace std;
-int main(){
- int n,x,y,z,i,min=1000000,n1,n2,n3,temp,t=0;
- cin>>n>>x>>y>>z;
- for(i=0;i>n1>>n2>>n3;
- temp+=n1*x+n2*y+n3*z;
- if(temp> n >> x >> y >> z;
+ for (i = 0; i < n; i++)
+ {
+ temp = 0;
+ cin >> n1 >> n2 >> n3;
+ temp += n1 * x + n2 * y + n3 * z;
+ if (temp < min)
+ {
+ min = temp;
+ t = i + 1;
+ }
+ }
+ cout << t << " " << min;
+ return 0;
}
```
## 答案
```cpp
-
+if (temp < min)
+{
+ min = temp;
+ t = i + 1;
+}
```
## 选项
@@ -45,17 +74,29 @@ int main(){
### A
```cpp
-
+if (temp > min)
+{
+ min = temp;
+ t = i + 1;
+}
```
### B
```cpp
-
+if (temp < min)
+{
+ min = temp;
+ t = i - 1;
+}
```
### C
```cpp
-
+if (temp > min)
+{
+ min = temp;
+ t = i - 1;
+}
```
\ No newline at end of file
diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/2.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/2.exercises/solution.md"
index 746d347c2..35f4df970 100644
--- "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/2.exercises/solution.md"
+++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/2.exercises/solution.md"
@@ -15,42 +15,84 @@
要求从第s个数开始,数m个出列,第s个不出列
+以下程序实现了这一功能,请你填补空白处的内容:
+
+```cpp
+#include
+void JosePhus(int n, int m, int start)
+{
+ int i, *arr = new int[n];
+ int count = 1;
+ ;
+ for (i = 0; i < n; i++)
+ arr[i] = i + 1;
+ int sum = n;
+ while (count < n)
+ {
+ start--;
+ int index = (start + m - 1) % sum;
+ ______________
+ sum--;
+ count++;
+ }
+ std::cout << arr[0] << "\n";
+}
+int main(int argc, const char *argv[])
+{
+ int n, m, start;
+ std::cout << "请输入n,m,start:\n";
+ while (std::cin >> n >> m >> start)
+ {
+ JosePhus(n, m, start);
+ std::cout << "请输入n,m,start:\n";
+ }
+ return 0;
+}
+```
+
## template
```cpp
#include
-void JosePhus(int n, int m, int start) {
- int i, *arr = new int[n];
- int count = 1;;
- for(i = 0;i < n; i++)
- arr[i] = i + 1;
- int sum = n;
- while(count < n) {
- start--;
- int index = (start+m-1) % sum;
- for(i = index; i < sum-1; i++)
- arr[i] = arr[i+1];
- start = index + 1;
- sum--;
- count++;
- }
- std::cout<< arr[0] <<"\n";
+void JosePhus(int n, int m, int start)
+{
+ int i, *arr = new int[n];
+ int count = 1;
+ ;
+ for (i = 0; i < n; i++)
+ arr[i] = i + 1;
+ int sum = n;
+ while (count < n)
+ {
+ start--;
+ int index = (start + m - 1) % sum;
+ for (i = index; i < sum - 1; i++)
+ arr[i] = arr[i + 1];
+ start = index + 1;
+ sum--;
+ count++;
+ }
+ std::cout << arr[0] << "\n";
}
-int main(int argc, const char * argv[]) {
- int n, m, start;
- std::cout << "请输入n,m,start:\n";
- while(std::cin >> n >> m >> start) {
- JosePhus(n, m, start);
- std::cout << "请输入n,m,start:\n";
- }
- return 0;
+int main(int argc, const char *argv[])
+{
+ int n, m, start;
+ std::cout << "请输入n,m,start:\n";
+ while (std::cin >> n >> m >> start)
+ {
+ JosePhus(n, m, start);
+ std::cout << "请输入n,m,start:\n";
+ }
+ return 0;
}
```
## 答案
```cpp
-
+for (i = index; i < sum - 1; i++)
+ arr[i] = arr[i + 1];
+start = index + 1;
```
## 选项
@@ -58,17 +100,23 @@ int main(int argc, const char * argv[]) {
### A
```cpp
-
+for (i = index; i < sum - 1; i++)
+ arr[i] = arr[i + 1];
+start = index - 1;
```
### B
```cpp
-
+for (i = index; i < sum; i++)
+ arr[i] = arr[i - 1];
+start = index + 1;
```
### C
```cpp
-
+for (i = index; i < sum; i++)
+ arr[i] = arr[i - 1];
+start = index - 1;
```
\ No newline at end of file
diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/3.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/3.exercises/solution.md"
index d18031792..973ed704c 100644
--- "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/3.exercises/solution.md"
+++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/3.exercises/solution.md"
@@ -1,43 +1,133 @@
# 海港(port)
-海港(port)
-【问题描述】
+
+**问题描述**
+
小谢是海港的海关工作人员,每天都有许多船只到达海港,船上通常有很多来自不同国家的乘客。
+
小谢对这些到达海港的船只非常感兴趣,他按照时间记录下了到达海港的每一艘船只情况;对于第i艘到达的船,他记录了这艘船只到达的时间ti(单位:秒),船上的乘客数量Ki,以及每名乘客的国籍x(i,1),x(i,2),···,x(i,k)。
+
小谢统计了n艘船的信息,希望你帮忙计算出以每一艘船到达时间为止的24小时(24小时=86400秒)内所有乘船到达的乘客来自多少个不同的国家。
+
形式化的讲,你需要计算n条信息。对于输出的第i条信息,你需要统计满足:ti-86400=1,∑ki<=3×105,1<=x(i,j)<=105,1<=ti-1
+#include
+#include
+#include
+#include
+#include
+using namespace std;
+int a[100100];
+int people[500100];
+struct node
+{
+ int country;
+ int time;
+};
+queue q;
+int main()
+{
+ int n, sum = 0;
+ scanf("%d", &n);
+ for (int i = 1; i <= n; i++)
+ {
+ int t, p;
+ scanf("%d%d", &t, &p);
+ node temp;
+ temp.time = t;
+ for (int i = 1; i <= p; i++)
+ {
+ int cty;
+ scanf("%d", &cty);
+ temp.country = cty;
+ q.push(temp);
+ if (!people[cty])
+ sum++;
+ people[cty]++;
+ }
+ while (1)
+ {
+ node old;
+ old = q.front();
+ if (temp.time - 86400 >= old.time)
+ {
+ int tc = old.country;
+ _________________________
+ q.pop();
+ }
+ else
+ break;
+ }
+ cout << sum << endl;
+ }
+ return 0;
+}
+```
+
## template
```cpp
@@ -50,49 +140,59 @@
using namespace std;
int a[100100];
int people[500100];
-struct node{
- int country;
- int time;
+struct node
+{
+ int country;
+ int time;
};
-queueq;
-int main(){
- int n,sum=0;
- scanf("%d",&n);
- for(int i=1;i<=n;i++){
- int t,p;
- scanf("%d%d",&t,&p);
- node temp;
- temp.time=t;
- for(int i=1;i<=p;i++){
- int cty;
- scanf("%d",&cty);
- temp.country=cty;
- q.push(temp);
- if(!people[cty]) sum++;
- people[cty]++;
- }
- while(1){
- node old;
- old=q.front();
- if(temp.time-86400>=old.time)
- {
- int tc=old.country;
- people[tc]--;
- if(!people[tc]) sum--;
- q.pop();
- }
- else break;
- }
- cout< q;
+int main()
+{
+ int n, sum = 0;
+ scanf("%d", &n);
+ for (int i = 1; i <= n; i++)
+ {
+ int t, p;
+ scanf("%d%d", &t, &p);
+ node temp;
+ temp.time = t;
+ for (int i = 1; i <= p; i++)
+ {
+ int cty;
+ scanf("%d", &cty);
+ temp.country = cty;
+ q.push(temp);
+ if (!people[cty])
+ sum++;
+ people[cty]++;
+ }
+ while (1)
+ {
+ node old;
+ old = q.front();
+ if (temp.time - 86400 >= old.time)
+ {
+ int tc = old.country;
+ people[tc]--;
+ if (!people[tc])
+ sum--;
+ q.pop();
+ }
+ else
+ break;
+ }
+ cout << sum << endl;
+ }
+ return 0;
}
```
## 答案
```cpp
-
+people[tc]--;
+if (!people[tc])
+ sum--;
```
## 选项
@@ -100,17 +200,23 @@ int main(){
### A
```cpp
-
+people[tc]++;
+if (!people[tc])
+ sum--;
```
### B
```cpp
-
+people[tc]--;
+if (!people[tc])
+ sum++;
```
### C
```cpp
-
+people[tc]--;
+if (people[tc])
+ sum--;
```
\ No newline at end of file
--
GitLab