diff --git "a/winter-day5/\345\215\236\347\247\213\351\230\263/7-4 \344\272\214\345\210\206\346\237\245\346\211\276.cpp" "b/winter-day5/\345\215\236\347\247\213\351\230\263/7-4 \344\272\214\345\210\206\346\237\245\346\211\276.cpp" new file mode 100644 index 000000000..128b2570e --- /dev/null +++ "b/winter-day5/\345\215\236\347\247\213\351\230\263/7-4 \344\272\214\345\210\206\346\237\245\346\211\276.cpp" @@ -0,0 +1,30 @@ +#include +using namespace std; +int n,a[10086],x,zl=0,ans=0; +int main() +{ cin>>n; + for(int i=0;i>a[i]; + } + cin>>x; + int l=0,r=n-1; + while(l<=r){ + int mid=(l+r)/2; + ans++; + if(x==a[mid]){ + cout<a[mid]){l=mid+1;} + if(xa[mid]) { l=mid+1; } if(x+map对string进行映射+并查集寻找公共祖先处理。 + +储存数据: + +struct people { int sex; int id; }; mapmp1; + +并查集: + +int find(int x) { int rt = fa[x]; if (fa[x] != x) rt = find(fa[x]); return rt; } + +判断是否为五代以内: + +bool pd(int x,int y) { int cnt=1; while(x!=fa[x]&&y!=fa[y]) { x=fa[x]; y=fa[y]; ++cnt; if(cnt==5) { // cout<<"cnt"< +using namespace std; +int a[100010]; +int sum=0,n; +int main() +{ + cin>>n; + for(int i=1;i<=n*2;i++) + { + cin>>a[i]; + } + sort(a+1,a+1+n+n); + cout< +using namespace std; +int c,d,flag=0,g; +int a[110],b[110]; +int main() +{ + while(cin>>c) + { + + + for(int i=0;i>a[i]; + } + cin>>d; + for(int i=0;i>b[i]; + } + sort(a,a+c); + for(int i=0;i +using namespace std; +int fa[100001]; +int n,m; +string s1,s2,s3,s4; +struct people +{ + int sex; + int id; +}; +mapmp1; +int find(int x); +bool pd(int x,int y) +{ + int cnt=1; + while(x!=fa[x]&&y!=fa[y]) + { + x=fa[x]; + y=fa[y]; + ++cnt; + if(cnt==5) + { + + return 1; + } + if(x==y) + { + + return 0; + } + } + return 0; +} + +int main() +{ + cin>>n; + for(int i=1;i<=100005;++i) + { + fa[i]=i; + } + vector< vector >a(n); + int q=0; + for(int i=0;i>s1>>s2; + mp1[s1].id=++q; + a[i].push_back(s1); + a[i].push_back(s2); + } + for(int i=0;i4&&s2.substr(s2.size()-4,4)=="sson") + { + mp1[s1].sex=1; + fa[mp1[s1].id]=mp1[s2.substr(0,s2.size()-4)].id; + } + if(s2.size()>7&&s2.substr(s2.size()-7,7)=="sdottir") + { + mp1[s1].sex=0; + fa[mp1[s1].id]=mp1[s2.substr(0,s2.size()-7)].id; + } + if(s2[s2.size()-1]=='m') + { + mp1[s1].sex=1; + } + if(s2[s2.size()-1]=='f') + { + mp1[s1].sex=0; + } + } + cin>>m; + for(int i=1;i<=m;i++) + { + cin>>s1>>s2>>s3>>s4; + if (!mp1[s1].id||!mp1[s3].id) + cout<<"NA"< +#include +#include +using namespace std; +int t,n,c,a[100001]; +int pd(int x) +{ + int now=a[1]; + int pos=1; + for(int i=2;i<=n;i++) + { + if(a[i]-now>=x) + { + now=a[i]; + pos++; + } + if(pos>=c) + return 1; + } + return 0; +} +int main() +{ + scanf("%d%d", &n,&c); + for(int i=1;i<=n;i++) + { + scanf("%d", &a[i]); + } + sort(a+1,a+n+1); + int l=1; + int r=a[n]; + while(l<=r) + { + int mid=(l+r)/2; + if(pd(mid)==1) + { + l=mid+1; + } + else + r=mid-1; + } + cout< +using namespace std; +int a[1010]; +int sum=0,n; +int main() +{ + cin>>n; + for(int i=1;i<=n;i++) + { + cin>>a[i]; + } + sort(a+1,a+1+n); + for(int i=0;i +using namespace std; +const int maxn = 1e5+5; +int n; +int a[maxn]={}; +void adjust(int a[],int s,int m); +void heapsort(int a[],int n) +{ + for(int i=n/2;i>=1;i--) adjust(a,i,n); + for (int i = 1; i <= n; i++) cout<> n; + for (int i = 1; i <=n; i++) cin>>a[i]; + heapsort(a,n); + return 0; +} +void adjust(int a[],int s,int m) +{ + int t=a[s]; + for(int j=2*s;j<=m;j*=2){ + if(j=a[j]) break; + a[s]=a[j]; + s=j; + } + a[s]=t; +} diff --git "a/winter-day6/\345\215\236\347\247\213\351\230\263/\346\210\220\347\273\251\346\216\222\345\272\217.cpp" "b/winter-day6/\345\215\236\347\247\213\351\230\263/\346\210\220\347\273\251\346\216\222\345\272\217.cpp" new file mode 100644 index 000000000..fab5996f8 --- /dev/null +++ "b/winter-day6/\345\215\236\347\247\213\351\230\263/\346\210\220\347\273\251\346\216\222\345\272\217.cpp" @@ -0,0 +1,27 @@ +#include +using namespace std; +const int maxn=1e4+5; +int n; +struct stu +{ string name; + int mark; +}a[maxn]; +bool cmp1(stu a, stu b); +bool cmp2(stu a, stu b); +int main() +{ + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i].name >> a[i].mark; + sort(a, a + n, cmp1); + sort(a, a + n, cmp2); + for (int i = 0; i < n; i++) cout<< a[i].name <<" "<< a[i].mark< b.mark; +} +bool cmp2(stu a, stu b) +{ + return a.mark == b.mark && a.name < b.name; +} diff --git "a/winter-day6/\345\215\236\347\247\213\351\230\263/\346\234\200\346\216\245\350\277\221\347\245\236\347\232\204\344\272\272.cpp" "b/winter-day6/\345\215\236\347\247\213\351\230\263/\346\234\200\346\216\245\350\277\221\347\245\236\347\232\204\344\272\272.cpp" new file mode 100644 index 000000000..1c25a85b5 --- /dev/null +++ "b/winter-day6/\345\215\236\347\247\213\351\230\263/\346\234\200\346\216\245\350\277\221\347\245\236\347\232\204\344\272\272.cpp" @@ -0,0 +1,40 @@ +#include +#define ll long long +using namespace std; +long long ans; +const int N=5e5+2;int c[N],a[N],b[N],n; +bool cmp(int x,int y){return a[x]>a[i];b[i]=i; + } + stable_sort(b+1,b+1+n,cmp);//± + for(int i=1;i<=n;i++) a[b[i]]=i; + for(int i=n;i>=1;i--) + { + ans+=ask(a[i]-1); + add(a[i]); + } + printf("%lld\n",ans); + return 0; +} +void add(int x) +{ + while(x<=n) + { + c[x]++; + x+=(x&-x); + } + return; +} diff --git "a/winter-day6/\345\215\236\347\247\213\351\230\263/\347\233\264\346\216\245\346\217\222\345\205\245\346\216\222\345\272\217.cpp" "b/winter-day6/\345\215\236\347\247\213\351\230\263/\347\233\264\346\216\245\346\217\222\345\205\245\346\216\222\345\272\217.cpp" new file mode 100644 index 000000000..60bc149f0 --- /dev/null +++ "b/winter-day6/\345\215\236\347\247\213\351\230\263/\347\233\264\346\216\245\346\217\222\345\205\245\346\216\222\345\272\217.cpp" @@ -0,0 +1,30 @@ +#include +using namespace std; +int a[1100]; +int n; +int main() +{ + + while(cin>>n){ + for(int i=0;i>a[i]; + } + for(int i=1;i=0;j--){ + if(key +using namespace std; +int x; +int n; +const int maxn = 1e5+5; +int a[maxn]={}; +int main() +{ + cin>>n; + for (int i=0;i>x; + a[x]++; + } + for (int i=0; i