diff --git "a/winter-day5/\345\215\236\344\273\201\345\271\263/hanjia5-1.cpp" "b/winter-day5/\345\215\236\344\273\201\345\271\263/hanjia5-1.cpp" new file mode 100644 index 000000000..3b370e246 --- /dev/null +++ "b/winter-day5/\345\215\236\344\273\201\345\271\263/hanjia5-1.cpp" @@ -0,0 +1,15 @@ +#include +using namespace std; +int main() +{ + int n;cin>>n; + int a[n]; + int s=0; + for(int i=0;i>a[i]; + for(int i=0;i +using namespace std; +int main() +{ + int n; + cin>>n; + int a[2*n]; + for(int i=0;i>a[i]; + sort(a,a+2*n); + cout< +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) n=mid-1; + else return mid; + } + return -1; +} +int main() +{ + int n; + cin>>n; + int a[n]; + for(int i=0;i>a[i]; + cin>>x; + cout< +using namespace std; + +map>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>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; +} \ No newline at end of file diff --git "a/winter-day5/\345\215\236\344\273\201\345\271\263/hanjia5-6.cpp" "b/winter-day5/\345\215\236\344\273\201\345\271\263/hanjia5-6.cpp" new file mode 100644 index 000000000..829ede7e2 --- /dev/null +++ "b/winter-day5/\345\215\236\344\273\201\345\271\263/hanjia5-6.cpp" @@ -0,0 +1,42 @@ +#include +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) n=mid-1; + else return mid; + } + return -1; +} +int main() +{ + int n; + while(cin>>n) + { + int a[n]; + for(int i=0;i>a[i]; + sort(a,a+n); + for(int i=0;i>m; + while(m--) + { + cin>>x; + cout< +using namespace std; +int m,n; +int a[100005]; +bool is(int mid) +{ + int sitart=0; + int cc = 1; + for(int i=1;i=mid) + { + cc++; + sitart=i; + } + } + if(cc>=m) return 1; + else return 0; +} +int main() +{ + cin>>n>>m; + for(int i=0;i>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< +using namespace std; +int main () +{ + int n; + while(cin>>n) + { + int a[n],t; + for(int i=0;i>a[i]; + for(int i=1;i=0&&t + +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>t; + a[t]++; + } + for(int i=0;i<10000;i++) + { + if(a[i]!=0) + { + cout< + +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; +} diff --git "a/winter-day6/\345\215\236\344\273\201\345\271\263/hanjia6-5.cpp" "b/winter-day6/\345\215\236\344\273\201\345\271\263/hanjia6-5.cpp" new file mode 100644 index 000000000..a6954a991 --- /dev/null +++ "b/winter-day6/\345\215\236\344\273\201\345\271\263/hanjia6-5.cpp" @@ -0,0 +1,44 @@ +#include + +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 0; i--) { + swap(arr[0], arr[i]); + max_heapify(arr, 0, i - 1); + for(int i=0;i>len; + int arr[len]; + for(int i=0;i>arr[i]; + heap_sort(arr, len); + return 0; +} diff --git "a/winter-day6/\345\215\236\344\273\201\345\271\263/hanjia6-6.cpp" "b/winter-day6/\345\215\236\344\273\201\345\271\263/hanjia6-6.cpp" new file mode 100644 index 000000000..f92745c75 --- /dev/null +++ "b/winter-day6/\345\215\236\344\273\201\345\271\263/hanjia6-6.cpp" @@ -0,0 +1,43 @@ +#include +using namespace std; +int n; +void swap(int a[],int index1,int index2) +{ + int t; + t=a[index1];a[index1]=a[index2];a[index2]=t; +} +void quicksort(int a[],int be,int e)//be:begin e:end +{ + if(be>=e)return ; + int i=be,j=e; + int key=a[i]; + int temp; + while(i!=j) + { + while(ikey)j--; + while(ia[k])flag=0; + } + cout<>n; + for(int i=0;i>a[i]; + quicksort(a,0,n-1); + for(int k=0;k