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 ...
随机推荐
- iOS textView在调用textViewDidChange方法,中文输入的问题
有时候,需要在textViewDidChange处理时,在中文输入的情况下,例如输入“中”,对应的拼音“zhong”, 在textViewDidChange的方法里会把拼音也算进去:导致输入中文时也输 ...
- eslint (js代码检查)
eslint 是一个应用广泛的javascript代码检查工具. 能检测变量名重复等等... 1.安装 npm install -g eslint 2.初始化 会在当前目录下生成一个.eslintrc ...
- 某考试 T2 yja
2.1 Description 在平面上找 n 个点, 要求这 n 个点离原点的距离分别为 r1, r2, ..., rn. 最大化这 n 个点构成的凸包面积, 凸包上的点的顺序任意. 2.2 Inp ...
- maven生命周期和依赖的范围
转载:http://blog.csdn.net/J080624/article/details/54692444 什么是依赖? 当 A.jar 包用到了 B.jar 包时,A就对B产生了依赖: 在项目 ...
- PHP开发者实用的代码
一.查看邮件是否已被阅读 当你在发送邮件时,你或许很想知道该邮件是否被对方已阅读.这里有段非常有趣的代码片段能够显示对方IP地址记录阅读的实际日期和时间. <? error_reporting( ...
- Node 即学即用 笔记 思维导图
Node即学即用 REPL(Read-Evaluate-Print-Loop) console.log .clear .help .exit require('http') ...
- android WIFI信息获取
在androi中WIFI信息的获取能够通过系统提供的WIFI Service获取 [java] WifiManager wifi_service = (WifiManager)getSystemSe ...
- jquery 动态绑定bind()及模拟鼠标点击A链接
近来自觉前端有小小进步,幸而记之. 1.两个 css class 紧挨在一起 则在html元素中,要同时拥有这两个class,才能起作用 .block.db{ background-image:url ...
- Attribute(特性)
一向都觉得.NET的Attribute好神秘.一个方框框住的东西,置身于类.方法的头部,本身不在类或方法里面,但又会起作用,有时作用还很大,仿佛充满了魔力.简直给人一种无冕之王,幕后之黑手的感觉! 某 ...
- IIS老革命遇到的一些问题
今天部署一个网站到IIS,遇到了一些问题.老革命遇上新问题.前不久搞java,接触了一下tomcat,觉得真麻烦.而tomcat大概是java阵营中最简单的了吧.想不到,IIS7,友好的图形界面下,也 ...