首页 > 代码库 > 2016大连网赛

2016大连网赛

网赛的时候就是前三个小时过了后面五道,然后两个小时就没搞出啥了;账号密码都忘了,只好重新写一遍了;

 

hdu-5868

hdu-5869

hdu-5870

hdu-5871

hdu-5872

hdu-5873

hdu-5874

hdu-5875

hdu-5876

 

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <bits/stdc++.h>#include <stack>#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)#define mst(ss,b) memset(ss,b,sizeof(ss));#define ll long long;typedef  long long LL; template<class T> void read(T&num) {    char CH; bool F=false;    for(CH=getchar();CH<‘0‘||CH>‘9‘;F= CH==‘-‘,CH=getchar());    for(num=0;CH>=‘0‘&&CH<=‘9‘;num=num*10+CH-‘0‘,CH=getchar());    F && (num=-num);}int stk[70], tp;template<class T> inline void print(T p) {    if(!p) { puts("0"); return; }    while(p) stk[++ tp] = p%10, p/=10;    while(tp) putchar(stk[tp--] + ‘0‘);    putchar(‘\n‘);} const LL mod=1e9+7;const double PI=acos(-1.0);const LL inf=1e18;const int N=1e6+2000;const int maxn=2e5+50;const double eps=1e-8;int n,m,ans[maxn];pair<int,int>p;map<pair<int,int>,int>mp;queue<int>q,qu;inline void makepair(int u,int v){    p.first=u;    p.second=v;    mp[p]=1;}int main(){    int t;    read(t);    while(t--)    {        mp.clear();        read(n);read(m);        int u,v,s;        For(i,1,m)        {            read(u);read(v);            makepair(u,v);            makepair(v,u);        }        read(s);        while(!q.empty())q.pop();        while(!qu.empty())qu.pop();        For(i,1,n)        {            if(s==i)continue;            qu.push(i);        }        q.push(s);        ans[s]=0;        while(!q.empty())        {            int fr=q.front();            q.pop();            int siz=qu.size();            p.first=fr;            while(siz--)            {                int f=qu.front();                qu.pop();                p.second=f;                if(!mp[p])ans[f]=ans[fr]+1,q.push(f);                else qu.push(f);            }        }        int num=0;        For(i,1,n)        {            if(i==s)continue;            num++;            if(num<n-1)printf("%d ",ans[i]);            else printf("%d\n",ans[i]);        }    }    return 0;}/*题意:求一个点多边少的补图的一个起点到其他所有点的最短距离;思路:补图里面的边就是原图里面没有的边,那么每次就判断两个点之间在原图中是否有边,主要是原图里面边较少可以这样判断;*/

  

hdu-5877

 

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <bits/stdc++.h>#include <stack>#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)#define mst(ss,b) memset(ss,b,sizeof(ss));#define ll long long;typedef  long long LL; template<class T> void read(T&num) {    char CH; bool F=false;    for(CH=getchar();CH<‘0‘||CH>‘9‘;F= CH==‘-‘,CH=getchar());    for(num=0;CH>=‘0‘&&CH<=‘9‘;num=num*10+CH-‘0‘,CH=getchar());    F && (num=-num);}int stk[70], tp;template<class T> inline void print(T p) {    if(!p) { puts("0"); return; }    while(p) stk[++ tp] = p%10, p/=10;    while(tp) putchar(stk[tp--] + ‘0‘);    putchar(‘\n‘);} const LL mod=1e9+7;const double PI=acos(-1.0);const LL inf=1e18;const int N=1e6+2000;const int maxn=2e5+50;const double eps=1e-8;int a[maxn],b[maxn],c[maxn],cnt,sum[maxn],in[maxn],n;LL k,ans;vector<int>ve[maxn];int lowbit(int x){return x&(-x);}inline int query(int x){    int s=0;    while(x)    {        s+=sum[x];        x-=lowbit(x);    }    return s;}inline void update(int x,int num){    while(x<=cnt)    {        sum[x]+=num;        x+=lowbit(x);    }}inline int getpos(LL x){    int l=1,r=cnt;    while(l<=r)    {        int mid=(l+r)>>1;        if((LL)c[mid]>x)r=mid-1;        else l=mid+1;    }    return r;}void dfs(int cur){    int pos;    if(a[cur]==0)pos=cnt;    else pos=getpos(k/a[cur]);    ans=ans+query(pos);    int temp=getpos(a[cur]);    update(temp,1);    int len=ve[cur].size();    for(int i=0;i<len;i++)dfs(ve[cur][i]);    update(temp,-1);}int main(){    int t;    read(t);    while(t--)    {        read(n);read(k);        For(i,0,n)        {            ve[i].clear();            sum[i]=in[i]=0;        }        For(i,1,n)read(a[i]),b[i]=a[i];        sort(b+1,b+n+1);        c[1]=b[1];cnt=1;ans=0;        For(i,2,n)        {            if(b[i]==b[i-1])continue;            c[++cnt]=b[i];        }        int u,v,root;        For(i,1,n-1)        {            read(u);read(v);            ve[u].push_back(v);            in[v]++;        }        For(i,1,n)        {            if(in[i])continue;            root=i;            break;        }        dfs(root);        print(ans);    }        return 0;}/*题意:求每个节点u以及和它的祖先节点v满足a[u]*a[v]<=k的对数和;思路:dfs的过程中将树状数组中保留的是它的所有祖先节点的信息,可以离散化后进行询问,然后把这个点的信息更细到树状数组中,待它的所有节点都访问完了再删除,据说treap也可以做;*/

  

2016大连网赛