Codeforces Round #209 (Div. 2) C - Prime Number
传送门
题意
给出n个数及x,求
\]
分析
结果必然为\(x^{sum}\),sum的值首先取所有数的和减去最大值
然后暴力合并,具体原因我不太懂,只能附上CF的标准题解
Obviously, the answer is \(x^v\). Let \(sum = a1 + a2 + ... + an\). Also let $si = sum - ai $(the array of degrees). After that let's find value \(v\) by the following algorithm: Let's consider a sequence of degrees as decreasing sequence. Now we will perform the following operation until it's possible to perfom it. Take the minimum degree \(v\) from the array of degrees and calculate the number of elements \(cnt\), which have the same degree. If \(cnt\) multiples of \(x\), then replace all \(cnt\) elements by \(cnt / x\) elements of the form \(v + 1\). Since the sequence of degrees is a decreasing sequence, we can simply assign them to the end. If \(cnt\) is not a multiple of \(x\), then we found the required value \(v\). Also you need to check, that \(v\) is not greater then sum. Otherwise, \(v\) will be equals to sum.
详情见代码
代码
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
using namespace std;
#define ll long long
#define F(i,a,b) for(int i=a;i<=b;++i)
#define R(i,a,b) for(int i=a;i<b;++i)
#define mem(a,b) memset(a,b,sizeof(a))
#pragma comment(linker, "/STACK:102400000,102400000")
inline void read(int &x){x=0; char ch=getchar();while(ch<'0') ch=getchar();while(ch>='0'){x=x*10+ch-48; ch=getchar();}}
const ll mod=1e9+7;
int n,x,a[100100],num,t;
ll sum,cnt;
bool vis[100100];
ll mi(int x,ll cnt)
{
    ll ret=x,ans=1;
    while(cnt)
    {
        if(cnt&1) ans=(ans*ret)%mod;
        cnt>>=1,(ret*=ret)%=mod;
    }
    return ans;
}
int main()
{
    scanf("%d %d",&n,&x);
    F(i,1,n){ scanf("%d",a+i);sum+=(ll)a[i]; }
    sum-=a[n];t=a[n];
    num=0;
    F(i,1,n)
    {
        if(a[i]==a[n]) { num++;vis[i]=1; }
        a[i]=a[n]-a[i];
    }
    while(num%x==0&&t)
    {
            sum++;num/=x;t--;
            F(i,1,n) if(!vis[i])
            {
                a[i]--;
                if(a[i]==0) {num++;vis[i]=1;}
            }
        if(num==0) break;
    }
    //printf("%d\n",sum);
    printf("%lld\n",mi(x,sum));
    return 0;
}
Codeforces Round #209 (Div. 2) C - Prime Number的更多相关文章
- 二分查找/暴力 Codeforces Round #166 (Div. 2) B. Prime Matrix
		题目传送门 /* 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 */ #include <cstdio> #include < ... 
- Codeforces Round #209 (Div. 2)A贪心  B思路 C思路+快速幂
		A. Table time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ... 
- Codeforces Round #427 (Div. 2) B. The number on the board
		引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ... 
- Codeforces Round #209 (Div. 2) D. Pair of Numbers (模拟)
		D. Pair of Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard ... 
- Codeforces Round #585 (Div. 2) B. The Number of Products(DP)
		链接: https://codeforces.com/contest/1215/problem/B 题意: You are given a sequence a1,a2,-,an consisting ... 
- Codeforces Round #411 div 2 D. Minimum number of steps
		D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input st ... 
- Codeforces Round #491 (Div. 2) E - Bus Number  + 反思
		E - Bus Number 最近感觉打CF各种车祸.....感觉要反思一下, 上次读错题,这次想当然地以为18!肯定暴了longlong 而没有去实践, 这个题我看到就感觉是枚举每个数字的个数,但是 ... 
- Codeforces Round #246 (Div. 2) C. Prime Swaps(贪心,数论)
		题目链接:http://codeforces.com/contest/432/problem/C 首先由题意分析出:这些数是从1到n且各不相同,所以最后结果肯定是第i位的数就是i. 采用这样一种贪心策 ... 
- Codeforces Round #460 (Div. 2)-B. Perfect Number
		B. Perfect Number time limit per test2 seconds memory limit per test256 megabytes Problem Descriptio ... 
随机推荐
- 7.1——函数的定义,参数传递,return语句
			函数的定义: (1)函数体是一个作用域,函数体是一个语句块,定义了函数的具体操作 (2)函数的形参类似于局部变量,只是区别是它是在函数的形参列表中定义的. (3)C++是一种静态强类型语言,对于每一次 ... 
- Memcached 管理与监控工具 MemAdmin
			MemAdmin是一款可视化的Memcached管理与监控工具,基于 PHP5 & JQuery 开发,体积小,操作简单. 主要功能: 服务器参数监控:STATS.SETTINGS.ITEMS ... 
- PHP的资源类型
			PHP的资源类型 php的资源类型 常见的有:打开文件.数据库连接.图形画布等. 常用操作:创建.使用.释放. 以文件操作为示例: //文件路径 $file_url = './data.txt'; / ... 
- php之memcache学习
			php之memcache学习 简介: memcache是一个分布式高速缓存系统. 分布式是说可以部署在多台服务器上,实现集群效果: 高速是因为数据都是维护在内存中的: 特点和使用场景: 1.非持久化存 ... 
- BZOJ 4894 有向图 外向生成树个数
			4894: 天赋 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 191 Solved: 150[Submit][Status][Discuss] D ... 
- httpclient失败重连机制
			HttpClient 底层会默认超时自动重发3次,DefaultHttpRequestRetryHandler源码 /** * Create the request retry handler ... 
- Java第二次作业參考代码
			Java第二次作业參考代码 [程序11] 题目:有1.2.3.4四个数字,能组成多少个互不同样且无反复数字的三位数?都是多少? public class lianxi11 { public stati ... 
- Linux下怎么添加和查看PATH环境变量
			linux下查看和添加PATH环境变量来自:http://apps.hi.baidu.com/share/detail/32942984 $PATH:决定了shell将到哪些目录中寻找命令或程序,PA ... 
- 3.2.1 配置构建Angular应用——简单的笔记存储应用——编辑功能
			本节我们会接着上节课的内容,继续来完成使用Angular来创建简单的笔记存储应用,上一节课,我们完成了笔记的展示功能,本节课,我们来完成编辑功能. 编辑主要是两个功能:编辑现有的笔记以及创建新笔记.首 ... 
- 比 git log 更强大的 git reflog
			最近做了个骚操作 git checkout commitId 修改了部分内容 git add . git commit -m '修改了些东西' -> 此时git 会自动生成一个新的 comm ... 
