2019 Multi-University Training Contest 2

题号 A B C D E F G H I J K L
状态 .
.

. . Ο . . . . Ο Ο Ο

1005  Everything Is Generated In Equal Probability

//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<math.h>
#include<cmath>
#include<time.h>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<algorithm>
#include<numeric>
#include<stack>
#include<bitset>
#include<unordered_map>
const int maxn = 0x3f3f3f3f;
const double EI = 2.71828182845904523536028747135266249775724709369995957496696762772407663035354594571382178525166427;
const double PI = 3.141592653589793238462643383279;
//#ifdef TRUETRUE
//#define gets gets_s
//#endif
using namespace std;
long long p = 998244353;
long long quick(long long a, int b, int c)
{
    long long ans = 1;
    a = a % c;
    while (b != 0)
    {
        if (b & 1)
        {
            ans = (ans * a) % c;
        }
        b >>= 1;
        a = (a * a) % c;
    }
    return ans;
}
struct s
{
    long long a, b,ans;
}z[3010];
long long ans[3010], aa[3010];
int main(void)
{
    int i, j, k;
    long long zz = 2;
    z[1].a = 0;
    z[1].ans = 0;
    long long z3 = quick(3, p - 2, p);
    //printf("  %lld\n",z3);
    for (i = 2; i <= 3000; i++)
    {
        z[i].a = z[i - 1].a + zz;
        z[i].a %= p;

        z[i].ans = (z[i].a * z3) % p;

        zz += 2;
        zz %= p;
    }
    ans[1] = 0;
    aa[1] = 0;
    for (i = 2; i <= 3000; i++)
    {
        ans[i] = (ans[i - 1] + z[i].ans) % p;
        aa[i] = (ans[i] * quick(i, p - 2, p)) % p;
    }
    int N;
    while (~scanf("%d", &N))
    {
        printf("%lld\n", aa[N]);
    }
    return 0;
}

1010 Just Skip The Problem

//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<math.h>
#include<cmath>
#include<time.h>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<algorithm>
#include<numeric>
#include<stack>
#include<bitset>
#include<unordered_map>
const int maxn = 0x3f3f3f3f;
const double EI = 2.71828182845904523536028747135266249775724709369995957496696762772407663035354594571382178525166427;
const double PI = 3.141592653589793238462643383279;
//#ifdef TRUETRUE
//#define gets gets_s
//#endif
using namespace std;
long long p = 1e6 + 3;
int main(void)
{
    long long n,i,ans;
    while (~scanf("%lld",&n))
    {
        if (n >= p)
        {
            printf("0\n");
            continue;
        }
        ans = 1;
        for (i = 1;i <= n;i++)
        {
            ans *= i;
            ans %= p;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

1011 Keen On Everything But Triangle

题意:给出n根火柴,q次询问,每次询问[l,r]区间内的火柴组成三角形的最长周长是多少。

思路:考虑暴力,必定是将l到r区间内的所有数字排序,然后从大到小依次check相邻的三根火柴能否组成三角形。

  考虑优化,由斐波那契数列的性质可得,45根1e9范围内的火柴必定能组成一个三角形(最坏情况是1,1,2,3,5,第45项就超过1e9了),所以线段树区间维护46个最大值,然后做上面的check就可以了。

#include<bits/stdc++.h>
#define clr(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=200010;
struct node{
    int l,r,size;
    ll a[50];
}tr[maxn<<2];
ll val[maxn];
int n,q;
inline ll rd()
{
    ll 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;
}
inline void pushup(int o,int oa,int ob){
    int i=1,j=1,k=0;
    while(++k<=tr[o].size){
        if(i<=tr[oa].size&&tr[oa].a[i]>=tr[ob].a[j]){
            tr[o].a[k]=tr[oa].a[i];
            i++;
        }else{
            tr[o].a[k]=tr[ob].a[j];
            j++;
        }
    }
}
inline void build(int o,int l,int r){
    tr[o].size=min(r-l+1,46);
    for(int i=1;i<=tr[o].size;i++){
        tr[o].a[i]=0;
    }
    if(l==r){
        tr[o].a[1]=val[l];
        return;
    }
    int mid=(l+r)>>1;
    build(o<<1,l,mid);
    build(o<<1|1,mid+1,r);
    pushup(o,o<<1,o<<1|1);
}
ll ans[50],temp[50];
int top=0;
inline void query(int o,int l,int r,int ql,int qr){
    if(ql<=l&&r<=qr){
        int si=min(46,top+tr[o].size);
        int i=1,j=1,k=0;
        while(++k<=si){
            if(i<=top&&ans[i]>=tr[o].a[j]){
                temp[k]=ans[i];
                i++;
            }else{
                temp[k]=tr[o].a[j];
                j++;
            }
        }
        top=si;
        for(int i=1;i<=top;i++){
            ans[i]=temp[i];
        }
        for(int i=top+1;i<=46;i++){
            ans[i]=0;
        }
        return;
    }
    int mid=(l+r)>>1;
    if(ql<=mid)query(o<<1,l,mid,ql,qr);
    if(mid<qr)query(o<<1|1,mid+1,r,ql,qr);
}
int main(){
    while(cin>>n>>q){
        for(int i=1;i<=n;i++){
//            scanf("%lld",&val[i]);
            val[i]=rd();
        }
        build(1,1,n);
        while(q--){
            int l,r;
            top=0;
            l=rd(),r=rd();
            query(1,1,n,l,r);
            ll an=-1;
            for(int i=1;i<=top-2;i++){
                if(ans[i]<ans[i+1]+ans[i+2]){
                    an=ans[i]+ans[i+1]+ans[i+2];
                    break;
                }
            }
            printf("%lld\n",an);
        }
    }
}

1012 Longest Subarray

题意:给出n个数字,求一个最长子串,要求这个串包含的数字的次数必定大于等于k。

思路:先将整体的字符串,次数小于k的数全部去掉,得到若干个不连续的子串,对这些子串递归做这个工作。调一下参数,递归到30层时直接return。

(这个做法可以被hack,但数据比较难造,赌出题人没有卡这个做法,队友tql)

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=b;i>=a;i--)
using namespace std;
#define ll long long
const int N=3e5+5;
const int mod = 998244353;
int a[301010],c[301010],q[301010];
int n,C,k,ans;
ll rd()
{
    ll 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;
}
void solve(int l,int r,int dep)
{
    if(dep>=30) return;
    //printf("l=%d r=%d\n",l,r);
    if(r-l+1<=ans) return;
    int flag=0,pre,cnt=0;
    rep(i,l,r) c[a[i]]=0;
    rep(i,l,r) ++c[a[i]];
    q[++cnt]=l-1;
    rep(i,l,r)
    {
        if(c[a[i]]<k)
        {
            q[++cnt]=i;
            flag=1;
        }
    }
    q[++cnt]=r+1;
    if(flag==0)
    {
        ans=r-l+1;
    }
    rep(i,1,cnt) solve(q[i]+1,q[i+1]-1,dep+1);
}
int main()
{
//    freopen("1.in","r",stdin);
//    freopen("1.out","w",stdout);
    while(~scanf("%d%d%d",&n,&c,&k))
    {
        ans=0;
        rep(i,1,n) a[i]=rd();
        solve(1,n,1);
        printf("%d\n",ans);
    }
}

原文地址:https://www.cnblogs.com/mountaink/p/11240079.html

时间: 2024-10-01 16:10:32

2019 Multi-University Training Contest 2的相关文章

2019 HDOJ Multi-University Training Contest Stage 8(杭电多校)

中规中矩的一场. 题目链接:http://acm.hdu.edu.cn/contests/contest_show.php?cid=855 C: 定义函数f(d,k)为数字d在数字k中出现的次数.给定d和x,找到尽量大的k使得k<=x且f(d,k)==k. 很诡异的一题,最好的做法仍然是打表找规律.题解给了一个很神奇的结论:满足条件的k<1011且k的分布非常稀疏. 1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* defin

2019 HDOJ Multi-University Training Contest Stage 10(杭电多校)

最后一场多校打得一般般. 题目链接:http://acm.hdu.edu.cn/contests/contest_show.php?cid=857 C: E: I: BFS水题. 1 /* Codeforces Contest 2019_mutc_10 2 * Problem I 3 * Au: SJoshua 4 */ 5 #include <queue> 6 #include <cstdio> 7 #include <vector> 8 #include <s

2019 HDOJ Multi-University Training Contest Stage 2(杭电多校)

服务器时不时爆炸,有点难受. 题目链接:http://acm.hdu.edu.cn/userloginex.php?cid=849 A: 神仙题.不可做题. B: dp. C: 推式子题. D: 边分治. E: 可以数学推理的题.但是显然打表更快找出规律.对打出来的结果做两次差分即可. 1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou doubl

2019 HDOJ Multi-University Training Contest Stage 4(杭电多校)

很抱歉过了这么多天才补这场,最近真的挺忙的…… 出题人是朝鲜的(目测是金策工业?),挺难. 题目链接:http://acm.hdu.edu.cn/contests/contest_show.php?cid=851 A: 签到题. 对于当前的点,若其编号为偶数,则可与1相连使得边权贡献为0.否则从低位向高位找当前点编号的二进制表示的第一个0,使这个0变为1,其他位置变为0并检查新的数字是否小于等于n.若小于等于n则贡献为0,反之贡献为1. 1 /* basic header */ 2 #inclu

2019 Nowcoder Multi-University Training Contest 1 H-XOR

由于每个元素贡献是线性的,那么等价于求每个元素出现在多少个异或和为$0$的子集内.因为是任意元素可以去异或,那么自然想到线性基.先对整个集合A求一遍线性基,设为$R$,假设$R$中元素个数为$r$,那么任取一个不在$R$内的元素,$R$中肯定存在一种取法能和这个元素异或和为$0$.同理,取定一个不在$R$内的元素,再随便取另外任意个不在$R$内的元素,$R$内仍然存在一种取法使得这个异或和为$0$.那么每个不在$R$内的元素包含在$2^{n - r - 1}$个集合内(其他不在$R$内的元素可以

HDU校赛 | 2019 Multi-University Training Contest 3

2019 Multi-University Training Contest 3 http://acm.hdu.edu.cn/contests/contest_show.php?cid=850 1004. Distribution of books 考虑二分答案,设当前二分出来的是\(x\). 设\(f_i\)表示前\(i\)个能分成最多的段数,使得每一段和都\(\leqslant x\). 转移显然,枚举一个\(j\),若\(s_i-s_j\leqslant x\)则转移,\(s_i\)表示前

[最短路,最大流最小割定理] 2019 Multi-University Training Contest 1 Path

题目:http://acm.hdu.edu.cn/showproblem.php?pid=6582 Path Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 3747    Accepted Submission(s): 1075 Problem Description Years later, Jerry fell in love

HDU4888 Redraw Beautiful Drawings(2014 Multi-University Training Contest 3)

Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description Alice and Bob are playing together. Alice is crazy about art and she has visited many museums around the world. She has

HDU 2018 Multi-University Training Contest 3 Problem A. Ascending Rating 【单调队列优化】

任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6319 Problem A. Ascending Rating Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 5943    Accepted Submission(s): 2004 Problem Description Before

2014 Multi-University Training Contest 6 Apple Tree(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 Apple Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 176    Accepted Submission(s): 120 Problem Description I've bought an orchard an