2018 HDU多校一补题

A:hdu6298

题意:
x + y + z = n x+y+z=n x+y+z=n
x ∣ n x|n xn , y ∣ n y|n yn , z ∣ n z|n zn
求最大的 x y z xyz xyz
题解:因为 x , y , z x,y,z x,y,z是n的因子,那么原式可以构造成 n a + n b + n c = n \frac{n}{a}+\frac{n}{b}+\frac{n}{c} = n an+bn+cn=n的形式

然后很容易发现: a , b , c a,b,c a,b,c最优只有两种,要么 a = 2 , b = 4 , c = 4 a=2,b=4,c=4 a=2,b=4,c=4,要么 a = b = c = 3 a=b=c=3 a=b=c=3
那么我们只要判断 n n n是不是4或者3的倍数就可以了

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<vector> 
using namespace std;
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mem(a,b) memset(a,b,sizeof(a));
#define lowbit(x)  x&-x;  
#define debugint(name,x) printf("%s: %d\n",name,x);
#define debugstring(name,x) printf("%s: %s\n",name,x);
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-6;
const int maxn = 1e5+5;
const int mod = 1e9+7;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
ll n;
int main() {
    int t;
    for(scanf("%d",&t);t;t--){
        scanf("%d",&n);
        if(n < 3) puts("-1");
        else{
            if(n%3 == 0) printf("%lld\n",n*n*n/27);
            else if(n%4 == 0) printf("%lld\n",n*n*n/(4*4*2));
            else printf("-1\n");
        }
    }
}

B:hdu6299

题意:给你n个括号串,要求你重新将n个串排序拼接,然后能够构成尽量多的 “()“,求出能够获得的类似((()))的最长序列(具体题意还是要看题。。。)

题解:求单个串的最大括号匹配数就是经典的栈问题,栈中剩下的字符那肯定是“))))((((“这种的形式。
接下去为了重新拼接多个串满足最大条件。首先要想,拼接后的串的最左端一定是))))这种无法和后面的((((匹配的字符,所以一定要让最左端的)))尽量少,所以贪心策略要先满足右括号尽量少。。然后就是各种XJB贪心策略一顿乱试

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<vector> 
using namespace std;
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mem(a,b) memset(a,b,sizeof(a));
#define lowbit(x)  x&-x;  
#define debugint(name,x) printf("%s: %d\n",name,x);
#define debugstring(name,x) printf("%s: %s\n",name,x);
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-6;
const int maxn = 1e5+5;
const int mod = 1e9+7;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,_;
struct node{
    int l,r;
    bool operator<(const node b)const{
        if(l >= r && b.l < b.r) return false;
        if(l < r && b.l >= b.r) return true;
        if(l >= r && b.l >= b.r) return r > b.r;
        return l < b.l;
    }
}w[maxn];
char s[maxn];
int main() {
    for(scanf("%d",&_);_;_--){
        scanf("%d",&n);
        stack<char>st;
        int ans = 0;
        for(int i = 1; i <= n; i++){
        	w[i].l = 0,w[i].r = 0; 
            while(!st.empty()) st.pop();
            scanf("%s",s);

            for(int j = 0;s[j]; j++){
                if(st.empty()) {
                    st.push(s[j]);
                    continue;
                }
                char ch = st.top();
                if(s[j] == ')' && ch == '('){
                    ans += 2;
                    st.pop(); 
                }else{
                    st.push(s[j]);
                }
            }
            while(!st.empty()){
                char c = st.top();
                if(c == ')') w[i].l++;
                else w[i].r++;
                st.pop();
            }
        }
        sort(w+1,w+n+1);
        // for(int i = 1; i <= n; i++)
        //     printf("%d %d\n",w[i].l,w[i].r);
        int ls = 0, rs = w[1].r;
        for(int i = 2; i <= n; i++){
            if(w[i].l >= rs){
                ans += 2*rs;
                rs = w[i].r;
            }else{
                rs = rs-w[i].l+w[i].r;
                ans += 2*w[i].l; 
            }
        }
        printf("%d\n",ans);
    }
}

C:hdu6300
水题不说了

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<vector> 
using namespace std;
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mem(a,b) memset(a,b,sizeof(a));
#define lowbit(x)  x&-x;  
#define debugint(name,x) printf("%s: %d\n",name,x);
#define debugstring(name,x) printf("%s: %s\n",name,x);
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-6;
const int maxn = 1e5+5;
const int mod = 1e9+7;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
ll n;
struct node{
    int x,y,id;
    bool operator<(const node C)const{
        return x < C.x;
    }
}w[maxn];
int main() {
    int t;
    for(scanf("%d",&t);t;t--){
        scanf("%d",&n);
        for(int i = 1; i <= 3*n; i++){
            scanf("%d%d",&w[i].x,&w[i].y);
            w[i].id = i;
        }
        sort(w+1,w+3*n+1);
        for(int i = 1; i <= 3*n; i++){
            printf("%d%c",w[i].id,i%3==0?'\n':' ');
        }
    }
}

D:hdu6301

题意:m个区间,要求区间内数字各不相同,求字典序最小的序列

题解:
用一个数组记录每个区间右端点能够覆盖的最左端的位置,用一个set记录当前区间的最小可行解,那么如果当前位置在这个区间内,那么就只能从set中不断地取*begin(), 否则的话我们可以把之前在区间外的可行解插入set中,模拟一下就好。

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<vector> 
using namespace std;
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mem(a,b) memset(a,b,sizeof(a));
#define lowbit(x)  x&-x;  
#define debugint(name,x) printf("%s: %d\n",name,x);
#define debugstring(name,x) printf("%s: %s\n",name,x);
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-6;
const int maxn = 1e5+5;
const int mod = 1e9+7;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,pos[maxn],_;
struct node{
    int l,r;
    bool operator<(const node C)const{
        if(l == C.l) return r < C.r;
        return l < C.l;
    }
}w[maxn];
int pre[maxn],ans[maxn];
set<int>st;
int main() {
    for(scanf("%d",&_);_;_--){
        st.clear();
        scanf("%d%d",&n,&m);
        for(int i = 1; i <= n; i++) pre[i] = i;
        for(int i = 1; i <= n; i++) st.insert(i);
        for(int i = 1,l,r; i <= m; i++){
            scanf("%d%d",&l,&r);
            pre[r] = min(l,pre[r]);
        } 
        for(int i = n-1; i >= 1; i--)
            pre[i] = min(pre[i],pre[i+1]);
        int pl = 1;
        for(int i = 1; i <= n; i++){
            while(pl < pre[i]){
                st.insert(ans[pl]);
                pl++;
            }
            ans[i] = *st.begin();
            st.erase(ans[i]);
        }
        for(int i = 1; i <= n; i++)
            printf("%d%c",ans[i],i==n?'\n':' ');
    }
}

H:hdu6305

不想说太多,找找网上题解吧(笛卡尔树俺不会啊

#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#include <algorithm>
using namespace std;
 
typedef long long ll;
 
const int maxn = 1e6+10;
const ll mod = 1e9+7;
 
int l[maxn], r[maxn], vis[maxn], stk[maxn], inv[maxn], siz[maxn];
int n;
ll a[maxn];
 
int build() {
    int top = 0;
    for(int i=1;i<=n;i++) l[i] = r[i] = vis[i] = 0;
    for(int i=1;i<=n;i++){
        int k = top;
        while(k > 0 && a[stk[k - 1]] < a[i]) --k;
        if(k) r[stk[k-1]] = i;
        if(k<top) l[i] = stk[k];
        stk[k++] = i;
        top = k;
    }
    for(int i=1;i<=n;i++) vis[l[i]] = vis[r[i]] = 1;
    int ret = 0;
    for(int i=1;i<=n;i++) if(vis[i] == 0) ret = i;
    return ret;
}
 
void dfs(int root)
{
    siz[root]=1;
    if(l[root]){
        dfs(l[root]);
        siz[root]+=siz[l[root]];
    }
    if(r[root]){
        dfs(r[root]);
        siz[root]+=siz[r[root]];
    }
}
 
int main()
{
    int T;
    scanf("%d",&T);
    inv[1]=1;
    for(int i=2;i<maxn;i++)
        inv[i] = 1LL * inv[mod%i]*(mod-mod/i)%mod;
    while(T--)
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%lld",&a[i]);
        int root=build();
        for(int i=0;i<=n;i++)
            siz[i]=0;
        dfs(root);
        ll ans=1;
        for(int i=1;i<=n;i++)
            ans=ans*inv[siz[i]]%mod;
        ans=(ans*n)%mod*inv[2]%mod;
        printf("%lld\n",ans);
    }
    return 0;
}

K:hdu6308
题意:模拟时区转换,把东八区时间转换成其他时区的时间
题解:将时间转换成分钟进行计算,最后再转换回来,模拟一下就好了

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<vector> 
using namespace std;
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mem(a,b) memset(a,b,sizeof(a));
#define lowbit(x)  x&-x;  
#define debugint(name,x) printf("%s: %d\n",name,x);
#define debugstring(name,x) printf("%s: %s\n",name,x);
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-6;
const int maxn = 1e5+5;
const int mod = 1e9+7;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int h,m;
char s[10];
int main() {
    int _;
    for(scanf("%d",&_);_;_--){
        scanf("%d%d%s",&h,&m,s);
        int x = h*60+m;
        double z;
        sscanf(s+4,"%lf",&z);
        //printf("%f\n",z);
        char ch=s[3];
        int shi = z*10*6;
        // printf("%d\n",shi);
        // continue;
        if(ch == '-') shi = -shi;
        shi -= 8*60;
        x += shi;
        //printf("%d\n",x);
        x += 24*60;
        int hour = x/60%24;
        int minu = x-x/60*60;
        if(hour < 10 && minu < 10)
            printf("0%d:0%d\n",hour,minu);
        else if(hour < 10)
            printf("0%d:%d\n",hour,minu);
        else if(minu < 10)
            printf("%d:0%d\n",hour,minu);
        else
            printf("%d:%d\n",hour,minu);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值