Codeforces 1114 - A/B/C/D/E/F - (Undone)

链接:http://codeforces.com/contest/1114


A - Got Any Grapes?

题意:甲乙丙三个人吃葡萄,总共有三种葡萄:绿葡萄、紫葡萄和黑葡萄,甲乙丙三个人至少要各自吃 $x,y,z$ 个葡萄,又甲只吃绿葡萄,乙不吃黑葡萄,丙三种颜色都吃。现在总共有 $a$ 个绿葡萄、$b$ 个紫葡萄、$c$ 个黑葡萄。要确认这么多葡萄能否使得三个人都满意。

题解:优先满足甲,剩下的绿葡萄加紫葡萄满足乙,最后再剩下的看看能不能满足丙。

AC代码:

#include<bits/stdc++.h>
using namespace std;
int x,y,z,a,b,c;
int main()
{
    cin>>x>>y>>z>>a>>b>>c;
    if(a>=x && (a-x)+b>=y && a-x+b-y+c>=z) cout<<"YES\n";
    else cout<<"NO\n";
}

B - Yet Another Array Partitioning Task - [贪心]

题意:将一个长度为 $n$ 的数组分成 $k$ 段,每段元素至少要有 $m$ 个,设每一段都有一个“漂亮程度”为该段的前 $m$ 大的元素之和,求如何分割这个数组,使得每一段的“漂亮程度”之和最大。

题解:这个数组的前 $m \cdot k$ 大个元素就是答案,假设这 $m \cdot k$ 个元素的集合为 $S$。那么如何分割,即在原数组中枚举,每累计遇到 $m$ 个属于 $S$ 的元素,就在这个位置划一刀,然后重新开始累计即可。

AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define mk(x,y) make_pair(x,y)
#define a(p) (p.first)
#define b(p) (p.second)
const int maxn=2e5+5;
int n,m,k;
int a[maxn];
bool t[maxn];
vector<pii> v;
int main()
{
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++) scanf("%d",&a[i]), v.push_back(mk(a[i],i));
    sort(v.begin(),v.end(),greater<pii>());
    memset(t,0,sizeof(t));
    ll sum=0;
    for(int i=0;i<(m*k);i++) t[b(v[i])]=1, sum+=a(v[i]);
    cout<<sum<<endl;
    int cnt=0, seg=0;
    for(int i=1;i<=n;i++)
    {
        if(t[i]) cnt++;
        if(cnt==m)
        {
            cnt=0, seg++;
            if(seg<k) printf("%d ",i);
        }
    }
}

C - Trailing Loves (or L‘oeufs?) - [分解质因数]

题意:给定一个十进制下的 $n$,要求出 $n!$ 在 $b$ 进制下进行表示,其尾部有多少个零。

题解:

换句话说,其实就是算 $n!$ 最多能整除多少次 $b$。对 $b$ 分解质因数得 $b = {p_1}^{x_1}{p_2}^{x_2} \cdots {p_k}^{x_k}$,然后只要算出 $n!$ 对应的 ${p_1}^{y_1}{p_2}^{y_2} \cdots {p_k}^{y_k}$ 就很好办了。

然后用十进制举例,例如 $n = 12$,那么先考虑 $10$ 进制的 $10 = 2 \times 5$,然后 $n / 2 = 6$ 我们就可以知道 $1 \sim 12$ 有 $[2,4,6,8,10,12]$ 这六个 $2$ 的倍数,每个数至少能提供 $2$ 的 $1$ 次方,而其中又有一部分能多提供一些,即 $n / 2^2 = 3$,即有 $[4,8,12]$ 这三个数字至少能提供 $2$ 的 $2$ 次方,考虑到这三个数字前面已经计算过提供一次,所以可以看做这三个数又提供了三个 $1$ 次方,再然后 $n / 2^3 = 12 / 8 = 1$,即 $[8]$ 这一个数字还能再多提供一个 $1$ 次方。因此总结下来,计算 $n!$ 到底包含多少个 $p_i$ 的 $x$ 次方通过 $n/p_i + n/p_i^2 + \cdots $ 就可以算出来。

所以类似地,我们对 $p_1 \cdots p_k$,每个都算出 $n!$ 包含其多少次方,最后取 $\lfloor \frac{y_i}{x_i} \rfloor$ 的最小值。

AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef pair<ull,int> P;
#define mk(x,y) make_pair(x,y)
#define _1 first
#define _2 second

vector<P> p;
void dec(ull n)
{
    p.clear();
    for(ull i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            int cnt=0;
            while(n%i==0) n/=i, cnt++;
            p.push_back(mk(i,cnt));
        }
    }
    if(n>1) p.push_back(mk(n,1));
}

ull solve(ull n,ull p)
{
    ull base=1, res=0;
    while(base<=n/p)
    {
        base*=p;
        res+=n/base;
    }
    return res;
}

int main()
{
    ull n,b;
    cin>>n>>b;
    dec(b);
    ull ans=ULLONG_MAX;
    for(auto x:p) ans=min(ans,solve(n,x._1)/x._2);
    cout<<ans<<endl;
}

原文地址:https://www.cnblogs.com/dilthey/p/10389483.html

时间: 2024-08-29 14:38:10

Codeforces 1114 - A/B/C/D/E/F - (Undone)的相关文章

Codeforces 1136 - A/B/C/D/E/F - (Undone)

链接:https://codeforces.com/contest/1136/ A - Nastya Is Reading a Book - [二分] #include<bits/stdc++.h> using namespace std; const int maxn=105; int n,l[maxn],r[maxn],k; int srch(int x) { int L=1, R=n; while(L<R) { int M=(L+R)>>1; if(l[M]<=x

Codeforces 8VC Venture Cup 2016 - Elimination Round F. Group Projects 差分DP*****

F. Group Projects There are n students in a class working on group projects. The students will divide into groups (some students may be in groups alone), work on their independent pieces, and then discuss the results together. It takes the i-th stude

Educational Codeforces Round 47 (Rated for Div. 2)F. Dominant Indices 线段树合并

题意:有一棵树,对于每个点求子树中离他深度最多的深度是多少, 题解:线段树合并快如闪电,每个节点开一个权值线段树,递归时合并即可,然后维护区间最多的是哪个权值,到x的深度就是到根的深度减去x到根的深度复杂度O(nlogn) //#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("

Educational Codeforces Round 61 (Rated for Div. 2)F(区间DP,思维,枚举)

#include<bits/stdc++.h>typedef long long ll;const int inf=0x3f3f3f3f;using namespace std;char b[507];int dp[507][507];int main(){    memset(dp,0x3f,sizeof(dp));    int n;    scanf("%d",&n);    scanf("%s",b+1);    for(int i=1;

Educational Codeforces Round 81 (Rated for Div. 2)F(线段树)

预处理把左集划分为大小为1~i-1时,把全部元素都移动到右集的代价,记作sum[i]. 然后枚举终态时左集的大小,更新把元素i 留在/移动到 左集的代价. 树状数组/线段树处理区间修改/区间查询 1 #define HAVE_STRUCT_TIMESPEC 2 #include<bits/stdc++.h> 3 using namespace std; 4 #define ll long long 5 const int N=2e5+7; 6 struct Tree{ 7 ll minn,la

Codeforces Round #538 (Div. 2)

目录 Codeforces 1114 A.Got Any Grapes? B.Yet Another Array Partitioning Task C.Trailing Loves (or L'oeufs?) D.Flood Fill(区间DP) E.Arithmetic Progression(交互 二分 随机化) F.Please, another Queries on Array?(线段树 欧拉函数) Codeforces 1114 比赛链接 貌似最近平均难度最低的一场div2了...

Codeforces 474D Flowers

http://codeforces.com/problemset/problem/474/D 思路:F[i]=F[i-1]+(i>=K)F[i-k] 1 #include<cstdio> 2 #include<cmath> 3 #include<algorithm> 4 #include<cstring> 5 #include<iostream> 6 const int Mod=1000000007; 7 int K,sum[200005]

[2016-03-27][HDU][1114][Piggy-Bank]

时间:2016-03-27 16:37:56 星期日 题目编号:[2016-03-27][HDU][1114][Piggy-Bank] 遇到的问题:注意f == e的情况,即dp[0] = 0; #include <cstring> #include <cstdio> #include<algorithm> using namespace std; int dp[10000 + 10]; int w[500 + 10],c[500 + 10]; int main(){

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ