Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

day5 #876

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

day5 #876

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions winter-day5/刘天阳/7-1 相邻数对.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <bits/stdc++.h>
using namespace std;

int n;
int a[10006];
bool vis[10006];

int main()
{
int ans = 0;
int n; cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i], vis[a[i]] = 1;
for (int i = 0; i <= 10000; i++) if(vis[i] && vis[i+1]) ans++;
cout << ans;

return 0;
}
26 changes: 26 additions & 0 deletions winter-day5/刘天阳/7-3 两个有序序列的中位数.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+7;
int a[N], b[N];
int main()
{
int cnt = 0, n; cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
int al = 1, bl = 1, ans = a[1];
while(cnt < (2*n+1)/2)
{
cnt++;
if(al <= n && (bl == n+1 || a[al] <= b[bl])) {
ans = a[al];
al++;
}
else {
ans = b[bl];
bl++;
}
// printf("ans = %d\n",ans);
}
cout << ans;
return 0;
}
27 changes: 27 additions & 0 deletions winter-day5/刘天阳/7-4 二分查找.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <bits/stdc++.h>
using namespace std;
int sum = 0;
int erf(int a[], int x, int n)
{
int l = 0, r = n-1;
while(l <= r)
{
sum++;
int m = (l+r)/2;
if(x == a[m]) return m;
if(x > a[m]) l = m + 1;
else r = m - 1;
}
return -1;
}
int main()
{
int n, a[10009], x, ans;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
cin >> x;

ans = erf(a, x, n);
cout << ans << endl << sum;
return 0;
}
34 changes: 34 additions & 0 deletions winter-day5/刘天阳/7-6 二分查找.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, a[1009];
while(cin >> n)
{
int k = n;
for (int i = 1; i <= n; i++) cin >> a[i];
// for (int i = 1; i <= n; i++) {
// cout << a[i];
// if(i < n) cout << " ";
// else cout << endl;
// }
sort(a+1, a+1+n);
for (int i = 1; i <= n; i++) {
cout << a[i];
if(i < n) cout << " ";
else cout << endl;
}
int m; cin >> m;
while(m--)
{
int b, ans = 0; cin >> b;
for (int i = 1; i <= n; i++)
if(a[i] == b) ans = i;
cout << ans;
if(m) cout << " ";
else cout << endl;
}
}

return 0;
}
15 changes: 15 additions & 0 deletions winter-day5/刘天阳/day5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
**7-1 相邻数对**

暴力枚举即可

**7-3 两个有序序列的中位数**

合并再进行排序

**7-4 二分查找**

二分查找,递归

**7-6 二分查找**

二分
26 changes: 26 additions & 0 deletions winter-day6/刘天阳/7-1 直接插入排序.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <bits/stdc++.h>
using namespace std;
int a[1009];
int main()
{
int n;
while(cin >> n){


for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
for (int i = 3; i <= n+1; i++)
{
sort(a+1,a+i);
for (int j = 1; j <= n; j++)
{
cout << a[j];
if(j < n) cout << " ";
else cout << endl;
}
}
}
return 0;
}
26 changes: 26 additions & 0 deletions winter-day6/刘天阳/7-2 成绩排序.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <bits/stdc++.h>
using namespace std;
struct Std{
string name;
int chengji;
};
Std stu[1009];
bool cmp(Std stu1,Std stu2)
{
if(stu1.chengji > stu2.chengji) return 1;
else if(stu1.chengji < stu2.chengji) return 0;
else return stu1.name < stu2.name;
}
int main(){
int n; cin >> n;
for (int i = 1; i <= n; i++) {
cin >> stu[i].name >> stu[i].chengji;
}
sort(stu+1, stu+n+1,cmp);
for (int i = 1; i <= n; i++)
{
cout << stu[i].name << " " << stu[i].chengji << endl;
}

return 0;
}
21 changes: 21 additions & 0 deletions winter-day6/刘天阳/7-3 统计工龄.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <bits/stdc++.h>
using namespace std;
int a[10009];

int main()
{
int n; int k;
cin >> n;
int maxx = 0;
while(n--) {
cin >> k;
maxx = max(maxx, k);
a[k]++;
}

for (int i = 0; i <= maxx; i++)
{
if(a[i]) cout << i << ":" << a[i] << endl;
}
return 0;
}
11 changes: 11 additions & 0 deletions winter-day6/刘天阳/day5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
**7-1 直接插入排序**

插入排序,每输入一个数进行排序

**7-2 成绩排序**

用了结构体存储数据

**7-3 统计工龄**

用桶即可