HZNU 2019 Summer training 6

A - Infinite Sequence

CodeForces - 622A

题意:第一个数是1,接下来是1和2,接下来是1,2, 3,接下来是1,2,3, 4,问第n个数是什么

题解:找出第几轮在找出第几个

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long ll;

const int maxn = 1e2 + 10;

int main()
{
    ll n;
    while(~scanf("%lld",&n)) {
        ll tmp;
        tmp = sqrt(2 * n * 1.0);
        if(tmp * (tmp + 1) > 2 * n)
            tmp--;
        if(n - (tmp * (tmp + 1)) / 2  == 0)
            printf("%lld\n",tmp);
        else
            printf("%lld\n",n - (tmp * (tmp + 1)) / 2);
    }
}

B - Not Equal on a Segment

CodeForces - 622C

题意:给你一个数组,给你m个询问,每个询问一个区间, 一个数值,在区间里哪一个位置不是这个数值,输出任意一个就行

题解:找到区间里的不一样的两个数字比较一下就好了

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long ll;

const int maxn = 2e5 + 10;
int a[maxn];
struct node{
    int st,en;
    int ans;
}b[maxn];
int flag[maxn];
int main()
{
    int n, q;
    scanf("%d %d", &n, &q);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    int pos = 0;
    for (int i = 1; i <= n; i++)
    {
        if(i == 1)
        {
            b[pos].st = i;
            b[pos].ans = a[i];
        }
        else
        {
            if(a[i] != a[i-1])
            {
                b[pos].en = i - 1;
                pos++;
                b[pos].st = i;
                b[pos].ans = a[i];
            }
        }
    }
    b[pos].en = n;
    int id = 1;
    for(int i=0;i<=pos;i++)
    {
        for(int j=b[i].st;j<=b[i].en;j++)
            flag[j] = id;
        id++;
    }

//    for(int i=0;i<=pos;i++)
//        printf("%d %d %d\n",b[i].st,b[i].en,b[i].ans);
//    cout<<endl;
//    for(int i=1;i<=n;i++)
//        printf("%d ",flag[i]);

    while(q--)
    {
        int l,r,x;
        scanf("%d %d %d",&l,&r,&x);
        if(flag[l] == flag[r] && a[l] == x)
        {
            puts("-1");
            continue;
        }
        else if(flag[l] == flag[r] && a[r] != x)
        {
            printf("%d\n",l);
            continue;
        }
        else
        {
            int id1 = flag[l];
            id1--;
            if(b[id1].ans != x)
                printf("%d\n",l);
            else
            {
                printf("%d\n",b[id1 + 1].st);
            }
        }
    }

}

C - Optimal Number Permutation

CodeForces - 622D

题意:用1-n组长度为2n的序列,要求每个数出现2次,假设位置分别为xi、yi(xi < yi),定义di = yi-xi。让你找到一种排列使得sigma((n-i) * |di+i-n|)最小。

题解:贪心+找规律

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long ll;

const int maxn = 2e6 + 10;
int a[maxn];
int main()
{
   int n;
   memset(a,0,sizeof a);
   scanf("%d",&n);
   int posa = 1;
   int posb = n + 1;
   for(int i=1;i<n;i++)
   {
        if(i % 2 == 1)
        {
            a[posa] = i;
            a[n + 1 - posa] = i;
            posa++;
        }
        else
        {
            a[posb] = i;
            a[3 * n - posb] = i;
            posb++;
        }
   }
   for(int i = 1;i <= 2 * n;i++)
   {
       if(a[i] == 0)
           printf("%d ",n);
       else
           printf("%d ",a[i]);

   }
}

D - Ants in Leaves

CodeForces - 622E

题意:给定一颗树,每个叶子节点上有一蚂蚁,除了根结点的之外的所有节点任意时刻至多只能有一个蚂蚁,每个蚂蚁每秒能移动到相邻的节点上,问所有蚂蚁移动到根结点的最短时间是多少。

题解:深度小的叶子蚂蚁先走,这样深度小的叶子蚂蚁就不用等深度大的叶子蚂蚁。然后算出每个子树走完的所需时间。d[i] = max(d[i - 1] + 1,d[i])


#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long ll;

const int maxn = 5e5 + 10;

int n;
vector<int>g[maxn],d;

void dfs(int u,int fa,int deep)
{
    if(g[u].size() == 1)
    {
        d.push_back(deep);
//        printf("%d\n",deep);
    }
    for(int i=0;i<g[u].size();i++)
    {
        int v = g[u][i];
        if(v == fa)
            continue;
        dfs(v,u,deep+1);
    }
}
int main()
{
    while(~scanf("%d",&n))
    {
        for(int i=1;i<=n;i++)
            g[i].clear();
        for(int i=1;i<n;i++)
        {
            int u,v;
            scanf("%d %d",&u,&v);
            g[u].push_back(v);
            g[v].push_back(u);
        }
        int ans = 0;
        for(int k = 0; k < g[1].size(); k++)
        {
            d.clear();
            dfs(g[1][k],1,1);
            sort(d.begin(),d.end());
            for(int i = 1; i < d.size(); i++)
            {

                d[i] = max(d[i - 1] + 1,d[i]);
                //cout<<d[i]<<endl;
            }
            ans = max(ans,d.back());
        }
        printf("%d\n",ans);
    }
    return 0;
}

E - The Sum of the k-th Powers

CodeForces - 622F

题意:求 mod (1e9 + 7)

原文地址:https://www.cnblogs.com/smallhester/p/11173966.html

时间: 2024-10-11 07:21:51

HZNU 2019 Summer training 6的相关文章

HZNU 2019 Summer training 6 -CodeForces - 622

A - Infinite Sequence  CodeForces - 622A 题目大意:给你一个这样的数列1,1,2,1,2,3,1,2,3,4,1,2,3,4,5....就是从1~n排列(n++).最后问你第n个位置是什么数字. 思路:如果你花点时间列数列的话会发现,1~n的最后一位对应的位置是1~n的和,那我们就大胆使用二分进行搜索这位数. #include<iostream> #include<algorithm> #include<cstdio> #incl

HZNU 2019 Summer training 4

A - Little C Loves 3 I CodeForces - 1047A 题意:一个数分成三份,每一个都不是3的倍数 题解:分成 (1, 1, n - 2) 或者分成(1, 2, n - 3 ) #include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include <vector> #in

HZNU 2019 Summer training 8

A - Petya and Origami CodeForces - 1080A 题意:制造一份邀请函需要2份a物品,5份b物品,8份c物品,一个盒子里面有k份物品(可以为a或b或c)问你制造n份邀请函需要用多少个盒子 题解:加起来就行了 #include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include &

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

HZNU 2019 Summer Selection contest 1

A - Nastya Is Buying Lunch CodeForces - 1136D B - Neko Performs Cat Furrier Transform CodeForces - 1152B C - TV Shows CodeForces - 1061D D - Pairs CodeForces - 1169B E - Increasing by Modulo CodeForces - 1169C F - Good Triple CodeForces - 1169D G - T

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&l

2019 Multi-University Training Contest 1 (补题)

1001.Blank 题意:给一列数组填四种数,使得每个给定第$i$个的区间数的种类刚好有$x_{i}$种 我的思路:dp,状态排完序后是四种数最后的位置,转移时判断合法性即可(卡常有点厉害) 代码: 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 const int N = 1e2 + 5; 5 const int MOD = 998244353; 6 7 int dp[2][N][N][N]; 8 int a[N][10]; 9

2019 Multi-University Training Contest 3

#include<bits/stdc++.h> using namespace std; typedef long long ll; const int S=8; ll mult_mod(ll a,ll b,ll c) { a%=c; b%=c; ll ret=0,tmp=a; while (b) { if (b&1) { ret+=tmp; if (ret>c) { ret-=c; } } tmp<<=1; if (tmp>c) tmp-=c; b>&g