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

brp #882

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

brp #882

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
15 changes: 15 additions & 0 deletions winter-day5/卞仁平/hanjia5-1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;cin>>n;
int a[n];
int s=0;
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
if(a[i]-a[j]==1||a[i]-a[j]==-1)
s++;
cout<<s;
return 0;
}
14 changes: 14 additions & 0 deletions winter-day5/卞仁平/hanjia5-2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int a[2*n];
for(int i=0;i<n+n;i++)
cin>>a[i];
sort(a,a+2*n);
cout<<a[n-1];
return 0;

}
28 changes: 28 additions & 0 deletions winter-day5/卞仁平/hanjia5-4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include<bits/stdc++.h>
using namespace std;
int sum=0;
int x;
int find(int a[],int q,int n)
{
n--;
while(n>=q)
{
sum++;
int mid=(n+q)/2;
if(a[mid]<x) q = mid+1;
else if(a[mid]>x) n=mid-1;
else return mid;
}
return -1;
}
int main()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++) cin>>a[i];
cin>>x;
cout<<find(a,0,n)<<endl;
cout<<sum;
return 0;
}
53 changes: 53 additions & 0 deletions winter-day5/卞仁平/hanjia5-5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include<bits/stdc++.h>
using namespace std;

map<string,pair<bool,string>>mp;

bool is(string a,string b)
{
int i=1,j;
for(string A=a;!A.empty();A=mp[A].second,i++)
{
j=1;
for(string B=b;!B.empty();B=mp[B].second,j++)
{
if(i>=5 && j>=5)
return 1;
if(A==B && (i<5 || j<5))
return 0;
}
}
return 1;
}

int main()
{
cin.sync_with_stdio(false);
int n,m;
string str,a,b;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a>>b;
if(b.back()=='n')
mp[a]={1,b.substr(0,b.size()-4)};
else if(b.back()=='r')
mp[a]={0,b.substr(0,b.size()-7)};
else if(b.back()=='m')
mp[a]={1,""};
else mp[a]={0,""};
}
cin>>m;
for(int i=1;i<=m;i++)
{
cin>>a>>str>>b>>str;
if(mp.find(a)==mp.end() || mp.find(b)==mp.end())
cout<<"NA\n";
else if(mp[a].first==mp[b].first)
cout<<"Whatever\n";
else if(is(a,b)==1) cout<<"Yes\n";
else cout<<"No\n";
}

return 0;
}
42 changes: 42 additions & 0 deletions winter-day5/卞仁平/hanjia5-6.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include<bits/stdc++.h>
using namespace std;
int x;
int find(int a[],int q,int n)
{
n--;
while(n>=q)
{
int mid=(n+q)/2;
if(a[mid]<x) q = mid+1;
else if(a[mid]>x) n=mid-1;
else return mid;
}
return -1;
}
int main()
{
int n;
while(cin>>n)
{
int a[n];
for(int i=0;i<n;i++) cin>>a[i];
sort(a,a+n);
for(int i=0;i<n;i++)
{
cout<<a[i];
if(i!=n-1) cout<<' ';
}
cout<<'\n';
int m;
cin>>m;
while(m--)
{
cin>>x;
cout<<find(a,0,n)+1;
if(m!=0) cout<<' ';
}
cout<<endl;
}

return 0;
}
39 changes: 39 additions & 0 deletions winter-day5/卞仁平/hanjia5-7.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

#include<bits/stdc++.h>
using namespace std;
int m,n;
int a[100005];
bool is(int mid)
{
int sitart=0;
int cc = 1;
for(int i=1;i<n;i++)
{
if(a[i]-a[sitart]>=mid)
{
cc++;
sitart=i;
}
}
if(cc>=m) return 1;
else return 0;
}
int main()
{
cin>>n>>m;
for(int i=0;i<n;i++) cin>>a[i];
sort(a,a+n);
int l=0,r=n-1,ans=1e9;
while(r>=l)
{
int mid=(r+l)/2;
if(is(mid))
{
ans=mid;
l=mid+1;
}
else r = mid-1;
}
cout<<ans;
return 0;
}
25 changes: 25 additions & 0 deletions winter-day5/卞仁平/寒假集训—day5(查找).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 寒假集训—day5(查找)

**7-1 相邻数对**

双重循环

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

一个数组直接sort,输出第n-1个

**7-4 二分查找**

二分查找

**7-5 冰岛人**

不会

**7-6 二分查找**

二分查找

**7-7 愤怒的牛**

二分答案
26 changes: 26 additions & 0 deletions winter-day6/卞仁平/hanjia6-1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <bits/stdc++.h>
using namespace std;
int main ()
{
int n;
while(cin>>n)
{
int a[n],t;
for(int i=0;i<n;i++)cin>>a[i];
for(int i=1;i<n;i++)
{
t=a[i];
int j;
for(j=i-1;j>=0&&t<a[j];j--)
a[j+1]=a[j];
a[j+1]=t;
for(int k=0;k<n;k++)
{
cout<<a[k];
if(k!=n-1) cout<<" ";
}
cout<<endl;
}
}
return 0;
}
24 changes: 24 additions & 0 deletions winter-day6/卞仁平/hanjia6-3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <bits/stdc++.h>

using namespace std;

int main ()
{
int n,t;
cin>>n;
int a[10000];
for(int i=0;i<10000;i++) a[i]=0;
for(int i=0;i<n;i++)
{
cin>>t;
a[t]++;
}
for(int i=0;i<10000;i++)
{
if(a[i]!=0)
{
cout<<i<<":"<<a[i]<<endl;
}
}
return 0;
}
38 changes: 38 additions & 0 deletions winter-day6/卞仁平/hanjia6-4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <bits/stdc++.h>

using namespace std;
const int maxn=5e5+10;
int n,a[maxn],r[maxn];
long long ans=0;
void mergesort(int s,int t)
{
int i,j,k,m;
if(s==t) return;
m=(s+t)/2;
mergesort(s,m);
mergesort(m+1,t);
i=s,j=m+1,k=s;
while(i<=m&&j<=t)
{
if(a[i]<=a[j])
{
r[k]=a[i]; i++; k++;
}
else
{
r[k]=a[j]; j++; k++;
ans+=m-i+1;
}
}
while(i<=m) { r[k]=a[i]; i++; k++; }
while(j<=t) { r[k]=a[j]; j++; k++; }
for(int i=s; i<=t; i++) a[i]=r[i];
}
int main()
{
scanf("%d",&n);
for(int i=1; i<=n; i++) scanf("%d",&a[i]);
mergesort(1,n);
printf("%lld\n",ans);
return 0;
}
44 changes: 44 additions & 0 deletions winter-day6/卞仁平/hanjia6-5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <bits/stdc++.h>

using namespace std;
void max_heapify(int arr[], int start, int end)
{
int dad = start;
int son = dad * 2 + 1;
while (son <= end)
{
if (son + 1 <= end && arr[son] < arr[son + 1])
son++;
if (arr[dad] > arr[son])
return;
else {
swap(arr[dad], arr[son]);
dad = son;
son = dad * 2 + 1;
}
}
}
void heap_sort(int arr[], int len)
{

for (int i = len / 2 - 1; i >= 0; i--)
max_heapify(arr, i, len - 1);

for(int i=0;i<len;i++) cout<<arr[i]<<" ";
cout<<endl;
for (int i = len - 1; i > 0; i--) {
swap(arr[0], arr[i]);
max_heapify(arr, 0, i - 1);
for(int i=0;i<len;i++) cout<<arr[i]<<" ";
cout<<endl;
}
}
int main()
{
int len;
cin>>len;
int arr[len];
for(int i=0;i<len;i++) cin>>arr[i];
heap_sort(arr, len);
return 0;
}
Loading