构造+贪心/数论


  为什么只有两个标题呢……因为第二题我不会……

怎样提高智商

  构造题……然而一开始半天我都yy不出来……

  后来我想:这题应该不会特别麻烦,而且既然样例只给了1,可能再给大一点就让人发现规律了……(心理战的可怕0.0?)然后yy了一下,发现全部都写0的答案是最多的,是$4*3^{n-1}$,然后就过了……

  唯一用到的是快速幂?

 //UOJ Round #5 A
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
using namespace std;
const int MOD=; void read(int &v){
v=; int sign=; char ch=getchar();
while(ch<'' || ch>'') {if (ch=='-') sign=-; ch=getchar();}
while(ch>=''&&ch<='') {v=v*+ch-''; ch=getchar();}
v*=sign;
}
typedef long long LL; LL pow_mod(int a,int b){
LL r=,base=a;
while(b){
if (b&) r=(r*base)%MOD;
base=base*base%MOD;
b>>=;
}
return r;
} int main(){
int n=;
read(n);
printf("%lld\n",pow_mod(,n-)*%MOD);
F(i,,n) printf("A 0 0 0 0\n");
return ;
}

怎样跑得更快

  Orz vfk&trz!

  这题真的是一道非常好的题!

  然而由于我实在太傻逼,直到现在才看懂vfk的题解……vfk的题解写的真的非常好,清晰易懂0.0

  感觉莫比乌斯反演真是好神奇>_<,不过做过这道题以后对莫比乌斯反演又有了些新的感悟?

  小范围枚举倍数or约数进行反演感觉更简单直观……易于理解……(然而大多数题目的数据范围都比较大?QwQ)

 //UOJ Round5 C
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
using namespace std;
typedef long long LL;
inline int getint(){
int r=,v=; char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if (ch=='-') r=-;
for(; isdigit(ch);ch=getchar()) v=v*-''+ch;
return r*v;
}
const int N=1e5+,P=;
/*******************template********************/ int n,c,d,q;
int b[N],f_r[N],f_z[N],hx[N],x[N],g[N];
inline void exgcd(LL a,LL b,LL &d,LL &x,LL &y){
if (!b){d=a;x=;y=;}
else {exgcd(b,a%b,d,y,x); y-=(a/b)*x;}
}
inline LL inv(int a){
LL d,x,y;
exgcd(a,P,d,x,y);
return d== ? (x+P)%P : -;
}
inline LL Pow(LL a,int b){
LL r=;
for(;b;b>>=,a=a*a%P) if (b&) r=r*a%P;
return r;
} void solve(){
F(i,,n) f_z[i]=(LL)b[i]*g[i]%P;
F(i,,n)
for(int j=i+i;j<=n;j+=i){
f_z[j]-=f_z[i];
if (f_z[j]<) f_z[j]+=P;
}
F(i,,n){
if (f_r[i]==- && f_z[i]!=){puts("-1");return;}
hx[i]=(LL)f_r[i]*f_z[i]%P;
}
D(i,n,)
for(int j=i+i;j<=n;j+=i){
hx[i]-=hx[j];
if (hx[i]<) hx[i]+=P;
}
F(i,,n) x[i]=(LL)hx[i]*g[i]%P;
F(i,,n) printf("%d%c",x[i],i==n?'\n':' ');
}
int main(){
#ifndef ONLINE_JUDGE
freopen("C.in","r",stdin);
freopen("C.out","w",stdout);
#endif
n=getint(); c=getint(); d=getint(); q=getint();
F(i,,n){
f_r[i]=Pow(i,abs(c-d));
if (c<d) f_r[i]=inv(f_r[i]);
}
F(i,,n) g[i]=Pow(Pow(i,d),P-);
F(i,,n)
for(int j=i+i;j<=n;j+=i){
f_r[j]-=f_r[i];
if (f_r[j]<) f_r[j]+=P;
}
F(i,,n) f_r[i]=inv(f_r[i]);
while(q--){
F(i,,n) b[i]=getint();
solve();
}
return ;
}

【UOJ Round #5】的更多相关文章

  1. 【UOJ Round #1】

    枚举/DP+排列组合 缩进优化 QAQ我当时一直在想:$min\{ \sum_{i=1}^n (\lfloor\frac{a[i]}{x}\rfloor + a[i] \ mod\ x) \}$ 然而 ...

  2. 【UOJ Round #8】

    A 一道不错的题,虽然大家都觉得是水题,然而蒟蒻我想出来的好慢……Orz alpq 发现其实就是一个网格图,每一个大块都是同一颜色……横纵坐标互不干扰…… //UOJ Round #8 A #incl ...

  3. 【UOJ Round #3】

    枚举/二分 C题太神窝看不懂…… 核聚变反应强度 QwQ很容易发现次小的公约数一定是gcd的一个约数,然后……我就傻逼地去每次算出a[1],a[i]的gcd,然后枚举约数……这复杂度……哦呵呵... ...

  4. 【CS round 34】Minimize Max Diff

    [题目链接]:https://csacademy.com/contest/round-34/task/minimize-max-diff/ [题意] 给你n个数字; 数组按顺序不下降; 让你删掉k个数 ...

  5. 【CS Round 34】Max Or Subarray

    [题目链接]:https://csacademy.com/contest/round-34/summary/ [题意] 让你找一个最短的连续子串; 使得这个子串里面所有数字or起来最大; [题解] 对 ...

  6. UOJ #30【CF Round #278】Tourists

    求从$ x$走到$ y$的路径上可能经过的最小点权,带修改  UOJ #30 $ Solution:$ 如果两个点经过了某个连通分量,一定可以走到这个连通分量的最小值 直接构建圆方树,圆点存原点的点权 ...

  7. UOJ #30. 【CF Round #278】Tourists

    Description Cyberland 有 n 座城市,编号从 1 到 n,有 m 条双向道路连接这些城市.第 j 条路连接城市 aj 和 bj.每天,都有成千上万的游客来到 Cyberland ...

  8. 【57.97%】【codeforces Round #380A】Interview with Oleg

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. 【42.86%】【Codeforces Round #380D】Sea Battle

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. 洛谷P2017 [USACO09DEC]晕牛Dizzy Cows [拓扑排序]

    题目传送门 晕牛Dizzy Cows 题目背景 Hzwer 神犇最近又征服了一个国家,然后接下来却也遇见了一个难题. 题目描述 The cows have taken to racing each o ...

  2. Prettier来统一代码风格

    prettier是一款解决代码风格问题的代码格式化工具,功能强大,简单易用,支持多语言,减少配置项. 前端开发过程中每个人写JavaScript的代码风格都不一样,又不能说别人写的代码有问题,这都是习 ...

  3. String、Date和Timestamp的互转

    begin 2018年8月17日19:09:49 String.Date和Timestamp的互转 String和Date的互转 关于String和Date的互转,在java8后会有不同.因为java ...

  4. Android- SharedPreferences 使用详解

    Android-SharedPreferences 使用详解 参考 https://developer.android.google.cn/reference/android/content/Shar ...

  5. Android-Binder原理浅析

    Android-Binder原理浅析 学习自 <Android开发艺术探索> 写在前头 在上一章,我们简单的了解了一下Binder并且通过 AIDL完成了一个IPC的DEMO.你可能会好奇 ...

  6. WEP/WPA-PSK密码破解工具aircrack-ng

    WEP/WPA-PSK密码破解工具aircrack-ng   aircrack-ng是Aircrack-ng工具集中的一个工具.该工具主要用于根据已经抓取的.cap文件或者.ivs文件破解出WEP/W ...

  7. python文件相关操作

    Python文件相关操作 打开文件 打开文件,采用open方法,会将文件的句柄返回,如下: f = open('test_file.txt','r',encoding='utf-8') 在上面的代码中 ...

  8. [Luogu5241]序列(DP)

    固定一种构造方法,使它能够构造出所有可能的序列. 对于一个要构造的序列,把所有点排成一串,若a[i]=a[i-1],那么从1所在弱连通块往连通块后一个点连,若所有点都在一个连通块里了,就在1所在强连通 ...

  9. VC6微软正则表达式greta使用案例

    #include <string> #include "regexpr2.h" using namespace std; using namespace regex;/ ...

  10. 使用 IntraWeb (16) - 基本控件之 TIWList、TIWListbox、TIWComboBox、TIWOrderedListbox

    TIWList //列表; 它对应 Html 中的 OL.LI(某些选项下会用表格模拟); TIWListbox 和 TIWComboBox 则对应 Html 在的 Option TIWListbox ...