2018HDU多校day1

1001(打表/不定方程)

这个可以直接打表。。然后发现。。如果不能被3或者4整除就是-1。。
然后被3整除一定是x=y=z=n/3(废话),否则被4整除一定是x=y=z/2=n/4。。

然后是严格证明。。
令u=n/x,v=n/y,w=n/z
有1/u+1/v+1/w=1
假设u<=v<=w,则u<=3
当u=2,1/v+1/w=1/2,v=w=4或w=3,v=6
当u=3,1/v+1/w=2/3,v=w=3
就只有这3种取法。。然后u=2,w=3,v=6如果能满足一定能满足3|n了。。直接取均值,可排除。。

/**
*         ┏┓    ┏┓

            ┏┛┗━━━━━━━┛┗━━━┓
            ┃       ┃  
            ┃   ━    ┃
            ┃ >   < ┃
            ┃       ┃
            ┃... ⌒ ...  ┃
            ┃ ┃
            ┗━┓ ┏━┛
             ┃ ┃ Code is far away from bug with the animal protecting          
             ┃ ┃ 神兽保佑,代码无bug
             ┃ ┃           
             ┃ ┃       
             ┃ ┃
             ┃ ┃           
             ┃ ┗━━━┓
             ┃ ┣┓
             ┃ ┏┛
             ┗┓┓┏━━━━━━━━┳┓┏┛
              ┃┫┫ ┃┫┫

              ┗┻┛ ┗┻┛
    */
    include<cstdio>
    include<cstring>
    include<algorithm>
    include<iostream>
    include<queue>
    include<cmath>
    include<map>
    include<stack>
    include<set>
    define inc(i,l,r) for(int i=l;i<=r;i++)
    define dec(i,l,r) for(int i=l;i>=r;i--)
    define link(x) for(edge *j=h[x];j;j=j->next)
    define mem(a) memset(a,0,sizeof(a))
    define ll long long
    define eps 1e-12
    define succ(x) (1<<x)
    define lowbit(x) (x&(-x))
    define sqr(x) ((x)*(x))
    define mid (x+y>>1)
    define NM 1000005
    define nm 2000005
    define N 1000005
    define M(x,y) x=max(x,y)

    const double pi=acos(-1);
    const ll inf=998244353;
    using namespace std;
    ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x10+ch-'0',ch=getchar();
    return fx;
    }

ll n;
int main(){
int =read();while(--){
n=read();
if(n%3==0)n/=3,printf("%lld\n",nnn);
else if(n%4==0)n/=4,printf("%lld\n",nnn*2);
else printf("-1\n");
}
return 0;
}

 

1002(6299)Balanced Sequence

题解:可以通过类似栈的操作把序列化成')))))','((((((',')))))((((('这样的三种形式,然后对于这个pair(a,b)按照玄学规则排序就OK(G++T了C++就过了)

#include <iostream>
#include <algorithm>
#include <string>
const int MAXN=1e5+10;
const int maxn=5e6+10;
using namespace std;
string s[MAXN];
char str[maxn];
typedef struct node{
    int h1,h2,id;
    friend bool operator<(node aa,node bb){
    if(min(aa.h1,bb.h2)==min(aa.h2,bb.h1))return aa.h1<bb.h2;
    return min(aa.h1,bb.h2)>min(aa.h2,bb.h1);
    }
}node;
node d[MAXN];
/*bool cmp(node aa,node bb){
        if(min(aa.h1,bb.h2)==min(aa.h2,bb.h1))return aa.h1<bb.h2;
	return min(aa.h1,bb.h2)>min(aa.h2,bb.h1);
}*/
int main(){
    //int _;cin>>_;
    ios::sync_with_stdio(false);
    int _;cin>>_;
    while(_--){
    int n;cin>>n;
    for(int i=1;i<=n;i++)cin>>s[i];
    int ans=0;
    for(int i=1;i<=n;i++){
        int _t=s[i].size();
        d[i].h1=d[i].h2=0;d[i].id=i;
        for(int j=0;j<_t;j++){
        if(s[i][j]=='(')d[i].h1++;
        else{
            if(d[i].h1>0)d[i].h1--;
            else{d[i].h2++;}
	     }
        }
    }
    sort(d+1,d+n+1);
//    sort(d+1,d+n+1);
    int cnt=0;
    for(int i=1;i<=n;i++){
        int _t=s[d[i].id].length();
        for(int j=0;j<_t;j++)str[++cnt]=s[d[i].id][j];
    }
    int a1=0,b1=0;
    for(int i=1;i<=cnt;i++){
        if(str[i]=='(')a1++;
        else{
        if(a1)a1--,ans++;
        else b1++;
        }
/*	ans+=2*min(b1,d[i].h2);
	b1-=min(b1,d[i].h2);
	b1+=d[i].h1;*/
    }
    ans*=2;
    cout<<ans<<endl;
   // for(int i=1;i<=n;i++)s[i].clear();
    }
    return 0;
}

1003(模拟)

模拟一下发现可以从左往右取,如果有x相同的可以取y最大或者y最小的。

/**
*         ┏┓    ┏┓

            ┏┛┗━━━━━━━┛┗━━━┓
            ┃       ┃  
            ┃   ━    ┃
            ┃ >   < ┃
            ┃       ┃
            ┃... ⌒ ...  ┃
            ┃ ┃
            ┗━┓ ┏━┛
             ┃ ┃ Code is far away from bug with the animal protecting          
             ┃ ┃ 神兽保佑,代码无bug
             ┃ ┃           
             ┃ ┃       
             ┃ ┃
             ┃ ┃           
             ┃ ┗━━━┓
             ┃ ┣┓
             ┃ ┏┛
             ┗┓┓┏━━━━━━━━┳┓┏┛
              ┃┫┫ ┃┫┫

              ┗┻┛ ┗┻┛
    */
    include<cstdio>
    include<cstring>
    include<algorithm>
    include<iostream>
    include<queue>
    include<cmath>
    include<map>
    include<stack>
    include<set>
    define inc(i,l,r) for(int i=l;i<=r;i++)
    define dec(i,l,r) for(int i=l;i>=r;i--)
    define link(x) for(edge *j=h[x];j;j=j->next)
    define mem(a) memset(a,0,sizeof(a))
    define ll long long
    define eps 1e-12
    define succ(x) (1<<x)
    define lowbit(x) (x&(-x))
    define sqr(x) ((x)*(x))
    define mid (x+y>>1)
    define NM 1000005
    define nm 2000005
    define N 1000005
    define M(x,y) x=max(x,y)

    const double pi=acos(-1);
    const ll inf=998244353;
    using namespace std;
    ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x10+ch-'0',ch=getchar();
    return fx;
    }

struct P{
int x,y,i;
bool operator<(const P&o){return x<o.x||(x==o.x&&y<o.y);}
}a[NM];
int n;

int main(){
int =read();while(--){
n=read()*3;
inc(i,1,n)a[i].x=read(),a[i].y=read(),a[i].i=i;
sort(a+1,a+1+n);
inc(i,1,n){
if(i%3)printf("%d ",a[i].i);else printf("%d\n",a[i].i);
}
}
}

 

 1004(6301)Distinct Values

题解:找到每个位置被限制的最左端点的位置 然后求这个区间的mex  弱鸡写了主席树做法 双制作+set的并没有想到

#include <bits/stdc++.h>
const int MAXN=1e5+10;
using namespace std;
typedef struct node{
    int l,r,vis;int len;
}node;
node d[MAXN*21];int rt[MAXN];
int cnt;
void update(int &x,int y,int l,int r,int t){
    x=++cnt;d[x]=d[y];d[x].len++;
  //  cout<<l<<"===----"<<r<<endl;
    if(l==r){
	//if(!d[x].vis)d[x].len=1,d[x].vis=1;
	return ;
    }
    int mid=(l+r)>>1;
    if(t<=mid)update(d[x].l,d[y].l,l,mid,t);
    else update(d[x].r,d[y].r,mid+1,r,t);
    d[x].len=d[d[x].l].len+d[d[x].r].len;
   // cout<<l<<" "<<r<<" "<<d[x].len<<endl;
}
int ans;
void querty(int x,int y,int l,int r){
    if(l==r){ans=l;return ;}
    int mid=(l+r)>>1;
  //  cout<<l<<"===="<<r<<" "<<d[d[y].l].len<<" "<<d[d[x].l].len<<endl;
    if(d[d[y].l].len-d[d[x].l].len!=mid-l+1)querty(d[x].l,d[y].l,l,mid);
    else querty(d[x].r,d[y].r,mid+1,r);
}
typedef struct Q{
   int l,r;
   friend bool operator<(Q aa,Q bb){
       if(aa.l==bb.l)return aa.r>bb.r;
       return aa.l<bb.l;
   }
}Q;
Q que[MAXN];
int ans1[MAXN],pre[MAXN];
int main(){
    int _;scanf("%d",&_);
    while(_--){
	int n,m;scanf("%d%d",&n,&m);
	cnt=0;
	for(int i=1;i<=m;i++)scanf("%d%d",&que[i].l,&que[i].r);
	sort(que+1,que+m+1);
	int be=1;
	for(int i=1;i<=m;i++){
	    while(be<que[i].l)pre[be]=0,ans1[be]=1,be++;
	    while(be<=que[i].r)pre[be]=que[i].l,be++;
	}
	for(;be<=n;be++)pre[be]=0,ans1[be]=1;
//	for(int i=1;i<=n;i++)cout<<pre[i]<<" ";
//	cout<<endl;
	int l=1;ans=1;int r=0;
	for(int i=1;i<=m;i++){
	    while(l<que[i].l)ans1[l]=1,rt[l]=rt[l-1],l++;
	    r=0;
	    while(l<=que[i].r){
		querty(rt[que[i].l-1],rt[l-1],1,n);ans1[l]=ans;
	//	cout<<l<<":::::"<<ans<<endl;
		update(rt[l],rt[l-1],1,n,ans);
	//	cout<<"--------"<<endl;
		l++;
	    }
	}
	for(;l<=n;l++)ans1[l]=1;
	for(int i=1;i<=n;i++){if(i==1)printf("%d",ans1[i]);else printf(" %d",ans1[i]);}
	printf("\n");
    }
}

1007队友博客https://blog.csdn.net/qkoqhh/article/details/81181298

1008(6305) RMQ Similar Sequence

题解:http://tokitsukaze.live/2018/07/23/hdu6305/

大佬的博客有详细题解 简单说只要证明B数组是一个排列 后面的做法就很显然...分治+st表

/*#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#pragma comment(linker, "/STACK:1024000000,1024000000")*/
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=1e6+10;
const ll mod=1e9+7;
//int n;
/*ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f*x;
}*/
struct FastIO
{
    static const int S=200;
    int wpos;
    char wbuf[S];
    FastIO():wpos(0){}
    inline int xchar()
    {
        static char buf[S];
        static int len=0,pos=0;
        if(pos==len) pos=0,len=fread(buf,1,S,stdin);
        if(pos==len) exit(0);
        return buf[pos++];
    }
    inline int read()
    {
        int s=1,c=xchar(),x=0;
        while(c<=32) c=xchar();
        if(c=='-') s=-1,c=xchar();
        for(;'0'<=c&&c<='9';c=xchar()) x=x*10+c-'0';
        return x*s;
    }
    ~FastIO()
    {
        if(wpos) fwrite(wbuf,1,wpos,stdout),wpos=0;
    }
}io;
ll ksm(ll a,ll b){
    ll ans=1ll;
    while(b){
    if(b&1)ans=ans*a%mod;
    a=a*a%mod;b>>=1;
    }
    return ans;
}
int a[MAXN];int pos[MAXN][22];
int mu[22],ma[MAXN];ll fav[MAXN],sum[MAXN];
int pmin(int aa,int bb){
    if(a[aa]==a[bb])return min(aa,bb);
    return a[aa]>a[bb]?aa:bb;
}
void St(int n){
    for(int i=1;i<=n;i++){pos[i][0]=i;
    for(int j=1;i+(1<<(j-1))<=n+1;j++)pos[i][j]=0;    
    }
    for(int j=1;mu[j-1]<=n;j++){
    for(int i=1;i+mu[j]<=n+1;i++){
        int t=mu[j-1];
       // if(dp[i][j-1]==dp[i+mu[j-1]][j-1])dp[i][j]=dp[i][j-1],pos[i][j]=min(dp[i][j-1],dp[i+mu[j-1]][j-1]);
       // else if(dp[i][j-1]>dp[i+mu[j-1]][j-1])dp[i][j]=dp[i][j-1],pos[i][j]=pos[i][j-1];
       // else dp[i][j]=dp[i+mu[j-1]][j-1],pos[i][j]=pos[i+mu[j-1]][j-1];
        pos[i][j]=pmin(pos[i][j-1],pos[i+t][j-1]);
    }
    }
}
int rmq(int l,int r){
   // int k=ma[r-l+1];
        int j=(int)(log10(r-l+1)/log10(2))+1;
    int i=r-(1<<(j-1))+1;
    return pmin(pos[l][j-1],pos[i][j-1]);
   // if(dp[l][k]==dp[r-mu[k]+1][k])return min(pos[l][k],pos[r-mu[k]+1][k]);
   // else if(dp[l][k]>dp[r-mu[k]+1][k])return pos[l][k];
   // else return pos[r-mu[k]+1][k];
  //  return pmin(pos[l][k],pos[r-mu[k]+1][k]);
}
ll C(int nn,int mm){
    //ll ret=1;
    if(mm<nn||nn<0) return 0;
   return  fav[nn]*fav[mm-nn]%mod*sum[mm]%mod;
    
}
namespace DFS
{
    struct node{int l,r;};
    int top;
    node st[MAXN];
    ll dfs(int mn,int mx)
    {
        ll res=1;
        int l,r;
        l=mn;
        r=mx;
        top=0;
        st[top].l=l;
        st[top++].r=r;
        while(top)
        {
            l=st[top-1].l;
            r=st[--top].r;
            if(l>=r) continue;
            int pos=rmq(l,r);
        //    res*=fav[p-l];res%=mod;res*=fav[r-p];res%=mod;res*=sum[r-l];res%=mod;
            res=res*C(pos-l,r-l)%mod;
            st[top].l=l;
            st[top++].r=pos-1;
            st[top].l=pos+1;
            st[top++].r=r;
        }
        return res;
    }
}

/*ll C(ll n,ll m){
    if(n>m) return 0;
    ll a=1,b=1;
    for(int i=m;i>=m-n+1;i--) a=a*i%mod;
    for(int i=1;i<=n;i++) b=b*i%mod;
    return (a*(ksm(b,mod-2)%mod)%mod);
}
ll Lucas(ll n,ll m){
    if(n==0) return 1;
    return (1ll*C(n%mod,m%mod)*Lucas(n/mod,m/mod))%mod;
}*/
int p;
ll dfs(int l,int r){
    //cout<<l<<" "<<r<<endl;
    if(l>=r)return 1LL;
  //  cout<<l<<" "<<r<<" "<<p<<endl;
    p=rmq(l,r);
   // cout<<l<<" "<<r<<" "<<p<<" "<<fav[p-l]<<" "<<res<<endl;
   // cout<<res<<endl;
  return dfs(l,p-1)*dfs(p+1,r)%mod*C(p-l,r-l)%mod;
    //dfs(rmq(l,r)+1,r);
}
int main(){
    int _;int n;
    _=io.read();
    mu[0]=1;//ma[0]=-1;
   // scanf("%d",&_);
    //cout<<_<<endl;
    for(int i=1;i<=21;i++)mu[i]=mu[i-1]*2;
   // for(int i=1;i<MAXN;i++)if(!(i&(i-1)))ma[i]=ma[i-1]+1;else ma[i]=ma[i-1];
    sum[0]=1;fav[0]=1;
    for(int i=1;i<MAXN;i++)sum[i]=i*sum[i-1]%mod,fav[i]=ksm(sum[i],mod-2);
    //cout<<Lucas(2,3)<<endl;
    while(_--){
    n=io.read();
//    scanf("%d",&n);
//    memset(dp,0,sizeof(dp));memset(pos,0,sizeof(dp));
    for(int i=1;i<=n;i++)a[i]=io.read();
    St(n);ll ans=DFS::dfs(1,n);
//    cout<<res<<endl;
    ans*=ksm((sum[n])%mod,mod-2);ans%=mod;
    ans*=n;ans%=mod;ans*=ksm(2ll,mod-2);ans%=mod;
    printf("%lld\n",ans);
    }
    return 0;
}

 

1011(6308)Time Zone

题解:模拟

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;scanf("%d",&n);double t;int x,y;
    while(n--){
	char ch='1';
	scanf("%d%d",&x,&y);
	while((ch!='+'&&ch!='-'))ch=getchar();
	scanf("%lf",&t);
	if(ch=='-')t*=-1;
	t-=8;bool flag=0;
	if(t<0)flag=1,t*=-1;
	t*=100;
//	cout<<t<<endl;
	int t3=round(t);
//	cout<<t3<<endl;
	int t1=t3/100;int t2=(t3/10-t1*10)*6;
//	cout<<t1<<" "<<t2<<endl;
	if(flag)t*=-1;
	if(t<0)x-=t1,y-=t2;
	else x+=t1,y+=t2;
	if(y<0)x--,y+=60;
	if(y>=60)x++,y-=60;
	if(x<0)x+=24;
	if(x>=24)x-=24;
	if(x<=9)printf("0%d:",x);
	else printf("%d:",x);
	if(y<=9)printf("0%d\n",y);
	else printf("%d\n",y);
    }
    return 0;
}

 

posted @ 2018-07-23 23:09  wang9897  阅读(153)  评论(0编辑  收藏  举报