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 ...
随机推荐
- msp430项目编程31
msp430中项目---无线通信系统31 1.SPI工作原理 2.nrf24l01工作原理 3.代码(显示部分) 4.代码(功能实现) 5.项目总结
- OO第三单元总结--根据JML写代码
一. JML语言 1. 理论基础 首先,JML不是JAVA的一部分,它是一群研究者为JAVA设计的扩展部分,但还没有得到官方的支持.因此,JAVA编译器并不支持JML,所以要想JML起作用,只能采用类 ...
- HashCode和equal方法
equals()反映的是对象或变量具体的值,即两个对象里面包含的值--可能是对象的引用,也可能是值类型的值. 而hashCode()是对象或变量通过哈希算法计算出的哈希值. 之所以有hashCode方 ...
- foobar2000播放dff格式音乐的解决办法
安装dff插件:http://www.foobar2000.org/components/view/foo_input_dsdiff 离线版本:链接:http://pan.baidu.com/s/1e ...
- 框架-弹出选择框(Jquery传递Json数组)
给一个button按钮,执行方法 Json传值$("body").on("click", "#btnsure", function() { ...
- zoom to raster resolution
don't execute the ESRI's command, just find out and write codes to zoom to the raster resolution. H ...
- 虚拟社会(Virtual Society)
虚拟社会(Virtual Society),又称赛博社会(Cyber Society),是指不同网民之间经由计算机.远程通讯终端等技术设备相互连接起来以进行信息的共享.互动与交流,并在其中进行社会交往 ...
- Spring Security教程(5)---- 国际化配置及UserCache
这一章是为了给后面的讲解打基础的,主要介绍下国际化的配置及UserCache的配置及使用 国际化配置 <!-- 定义上下文返回的消息的国际化 --> <bean id="m ...
- pycharm查看代码注释的方法,代码编写日志及作者信息等
竟然在边栏有个右键的快捷键.annotate可以查看代码书写日期及作者 鼠标悬停可以看到更加详细的时间等信息 原理应该是利用git blame
- Linux中查看文件或者文件夹大小
df -l 查看磁盘空间大小命令 df -hl 查看磁盘剩余空间 df -h 查看每个根路径的分区大小 du -sh 当前文件夹下所有文件大小(包括子文件大小 du -sm [文件夹] 返回该 ...