Codeforces 1062 - A/B/C/D/E - (Undone)

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


A - Prank - [二分]

题意:

给出长度为 $n(1 \le n \le 100)$ 的数组 $a[1 \sim n]$,且满足 $1 \le a[1] < a[2] < \cdots < a[n] \e 1000$。现在JATC要擦掉其中一段连续的数字,但是要求能够通过剩余的其他数字,推断出擦掉的数字是什么。求JATC能擦掉的最长长度。

题解:

其实 $O(n)$ 就可以求出能擦掉的最长长度,但是因为 $n$ 比较小,懒得考虑太多,直接二分吧……

二分能擦掉的长度,对于固定的长度,$O(n)$ 枚举始末点判断能否擦除即可。

AC代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn=105;
int n,a[maxn];
bool judge(int k)
{
    for(int i=1,j=i+k-1;j<=n;i++,j++) {
        if(a[j+1]-a[i-1]==k+1) return 1;
    }
    return 0;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    a[0]=0, a[n+1]=1001;
    int l=0, r=n;
    while(l<r)
    {
        int mid=(l+r+1)/2;
        if(judge(mid)) l=mid;
        else r=mid-1;
    }
    cout<<l<<endl;
}

B - Math - [数学题]

题意:

给出一个正整数 $n(1 \le n \le 1e6)$,你现在可以对 $n$ 进行任意多次乘以正整数 $x$ 或者开方(当结果为整数时才允许开方)操作。

求结果最小为多少,达到这个结果最少进行多少次操作。

题解:

分解质因数 $n = {p_1}^{a_1}{p_2}^{a_2} \cdots {p_k}^{a_k}$,显然最后结果只能是 $p_1 p_2 \cdots p_k$,那么如何才能得到 $p_1 p_2 \cdots p_k$?

找到 $\max(a_i)$,求得比小于它的最小 $2^x$,这样一来先做一次乘法把 $n$ 乘到 ${p_1}^{2^x}{p_2}^{2^x} \cdots {p_k}^{2^x}$,然后做 $2^x$ 次开方操作即可得到 $p_1 p_2 \cdots p_k$。因此最少 $x+1$ 次操作。

(当然,还有一些数字本身就是最小结果,这些另作判断即可。)

AC代码:

#include<bits/stdc++.h>
using namespace std;
int n;
pair<int,int> solve(int n)
{
    if(n<=1) return make_pair(n,0);
    int res=1,mx=0, mn=20;
    for(int i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            res*=i;
            int cnt=0;
            while(n%i==0) n/=i, cnt++;
            mx=max(cnt,mx);
            mn=min(cnt,mn);
        }
    }
    if(n>1) res*=n, mx=max(1,mx), mn=min(1,mn);
    int t=ceil(log2(mx))+1e-8;
    if(mn==mx && (1<<t)==mx) return make_pair(res,t);
    else return make_pair(res,t+1);
}
int main()
{
    while(cin>>n)
    {
        pair<int,int> ans=solve(n);
        cout<<ans.first<<‘ ‘<<ans.second<<endl;
    }
}

C - Banh-mi - []


D - Fun with Integers - []


E - Company - []

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

时间: 2024-10-30 20:36:42

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

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

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

2017 United Kingdom and Ireland Programming Contest - A ~ L - (Undone) - (Online)(Solved 10 problems)

链接:https://codeforces.com/gym/101606 A - Alien Sunset 暴力枚举小时即可. #include<bits/stdc++.h> using namespace std; const int maxn=23; int n; int h[maxn],r[maxn],s[maxn]; inline bool dark(int id,int time) { if(r[id]<s[id]) { if(r[id]<time &&

[最短路,floyd] Codeforces 1204C Anna, Svyatoslav and Maps

题目:http://codeforces.com/contest/1204/problem/C C. Anna, Svyatoslav and Maps time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The main characters have been omitted to be short. You are give

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b

Codeforces 841D Leha and another game about graph - 差分

Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or  - 1. To pass th

Codeforces Round #286 (Div. 1) A. Mr. Kitayuta, the Treasure Hunter DP

链接: http://codeforces.com/problemset/problem/506/A 题意: 给出30000个岛,有n个宝石分布在上面,第一步到d位置,每次走的距离与上一步的差距不大于1,问走完一路最多捡到多少块宝石. 题解: 容易想到DP,dp[i][j]表示到达 i 处,现在步长为 j 时最多收集到的财富,转移也不难,cnt[i]表示 i 处的财富. dp[i+step-1] = max(dp[i+step-1],dp[i][j]+cnt[i+step+1]) dp[i+st

Codeforces 772A Voltage Keepsake - 二分答案

You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power store