题目链接: https://www.nowcoder.com/acm/contest/181#question

A.斐波拉契

求$f[n-1]*f[n+1]-f[n]^2$,$f[n]$为斐波拉契数列第$n$项

算一下前几项不难发现答案为$(-1)^n$,下面用数学归纳法证明一下:

$n=2$时,猜想成立

假设$n=k$时猜想成立,即$f[k-1]*f[k+1]-f[k]^2=(-1)^k$

当$n=k$时,$f[k]f[k+2]-f[k+1]^2=f[k](f[k+1]+f[k])-f[k+1]*(f[k]+f[k-1])=f[k]^2-f[k-1]f[k+1]=(-1)^{k+1}$

得证

#include <cstdio>
#include <algorithm>
#include<vector>
#include<iostream>
#include<cstring>
char s[1000005];
using namespace std;
int main(){
scanf("%s",s);
int l=strlen(s);
int z=s[l-1]-'0';
if(z%2==0)
cout<<1<<endl;
else cout<<-1<<endl;
}

B.送分题

#include <cstdio>
#include <algorithm>
#include<vector>
#include<iostream>
using namespace std;
bool vis[10005];
int a[10005];
vector<int> ans;
int main(){
long long a,b;
cin>>a>>b;
cout<<a+b<<endl;
}

C.序列

暴力就好,先求出该序列每处的前缀和,用map表示该前缀和存在,对于每次查询,先判断k之前是否查询过,查询过则不用判断,再判断序列和是否是k的倍数,否则,对于$1(sum/z)~k(sum/z)$的前缀和是否都存在

#include <cstdio>
#include <algorithm>
#include<vector>
#include<iostream>
#include<cstring>
#include<map>
using namespace std;
typedef long long ll;
const int maxn=100005;
int ans[maxn]; ll a[maxn];
map<ll,int> mp; int main(){
int n,q;
scanf("%d%d",&n,&q);
ll sum=0;
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
sum+=a[i];
mp[sum]=1;
}
for(int i=1;i<=q;i++){
int z;
scanf("%d",&z);
if(z>n||sum%z!=0||ans[z]==2){
printf("No\n");
continue;
} if(ans[z]==1){
printf("Yes\n");
continue;
}
for(int i=1;i*(sum/z)<sum;i++){
if(mp[i*(sum/z)]!=1){
printf("No\n");
ans[z]=2;
break;
}
}
if(ans[z]!=2){
printf("Yes\n");
ans[z]=1;
}
}
}

D.小叶的巡查

求下直径就好了

#include <cstdio>
#include <algorithm>
#include<vector>
#include<iostream>
#include<cstring>
using namespace std;
const int maxn=100005;
vector< pair<int,int> > g[maxn];
int d[maxn];
bool vis[maxn];
void dfs(int u){
vis[u]=1;
for(int i=0;i<g[u].size();i++){
int v=g[u][i].first;
if(!vis[v]){
d[v]=d[u]+g[u][i].second;
dfs(v);
}
}
}
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<n;i++){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
g[x].push_back(make_pair(y,z));
g[y].push_back(make_pair(x,z));
}
// cout<<-1<<endl;
dfs(1);
int cnt;
long long dmax=0;
for(int i=1;i<=n;i++){
if(d[i]>dmax){
dmax=d[i];
cnt=i;
}
vis[i]=0;
d[i]=0;
}
dmax=0;
dfs(cnt);
for(int i=1;i<=n;i++){
if(d[i]>dmax){
dmax=d[i];
}
}
cout<<dmax*10+(1+dmax)*dmax/2<<endl;
}

E.旅行青蛙

最长上升子序列,但是感觉题意有问题,题目的描述应该是最长不上升子序列233,n比较大,用$O(n*log n)$的写法

#include <cstdio>
#include <algorithm>
#include<vector>
#include<iostream>
#include<cstring>
using namespace std;
const int maxn=100005;
int dp[maxn];
int a[maxn];
int n;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
int cnt=0;
dp[0]=-1e9;
for(int i=1;i<=n;i++){
if(a[i]>=dp[cnt]){
dp[++cnt]=a[i];
}
else {
int z=upper_bound(dp+1,dp+1+cnt,a[i])-dp;
dp[z]=a[i];
}
}
cout<<cnt<<endl;
}

F.子序列

由题意知,答案与序列的顺序无关,故先将序列排个序,对于序列中的第i个数,需要相乘的次数为$C{n-1}^{k-1}-C{i-1}^{k-1}-C_{n-i}^{k-1}$。又1e9+7为素数,根据欧拉公式$a^{p-1}\equiv1mod p$

即可得出答案

#include <cstdio>
#include <algorithm>
#include<vector>
#include<iostream>
#include<cstring>
#include<map>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int maxn=1005; ll pmod(ll a,ll b){
if(a==0) return 0;
if(b==0) return 1;
if(b==1) return a%mod;
ll ans=pmod(a,b/2);
ans=ans*ans%mod;
if(b&1)
return ans*a%mod;
return ans;
}
ll a[maxn];
ll c[maxn][maxn];
int main(){
for(int i=0;i<=1000;i++)
c[i][0]=1;
c[1][1]=1;
for(int i=1;i<=1000;i++)
c[i][i]=1;
for(int i=1;i<=1000;i++)
for(int j=1;j<i;j++)
c[i][j]=(c[i-1][j]+c[i-1][j-1])%(mod-1);
int t;
scanf("%d",&t);
while(t--){
int n,k;
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
scanf("%lld",&a[i]);
sort(a+1,a+1+n);
ll ans=1;
for(int i=2;i<n;i++){
ll z=c[n-1][k-1];
if(n-i>=k-1)
z-=c[n-i][k-1];
if(i-1>=k-1)
z-=c[i-1][k-1];
z=((z)%(mod-1)+mod-1)%(mod-1);
z=pmod(a[i],z);
ans=ans*z%mod;
}
printf("%lld\n",ans);
}
return 0;
}

  

牛客OI测试赛1的更多相关文章

  1. 关于斐波那契数列的一些恒等式 模板 牛客OI测试赛 A 斐波拉契

    牛客A 斐波拉契 链接:https://www.nowcoder.com/acm/contest/181/A来源:牛客网 设f[i]表示斐波那契数论的第i项 f[1]=1,f[2] =1,f[i] = ...

  2. 牛客OI测试赛 C 序列 思维

    链接:https://www.nowcoder.com/acm/contest/181/C来源:牛客网 题目描述 小a有n个数,他想把他们划分为连续的权值相等的k段,但他不知道这是否可行. 每个数都必 ...

  3. 牛客OI测试赛 F 子序列 组合数学 欧拉降幂公式模板

    链接:https://www.nowcoder.com/acm/contest/181/F来源:牛客网 题目描述 给出一个长度为n的序列,你需要计算出所有长度为k的子序列中,除最大最小数之外所有数的乘 ...

  4. 牛客oi测试赛 二 B 路径数量

    题目描述 给出一个 n * n 的邻接矩阵A. A是一个01矩阵 . A[i][j]=1表示i号点和j号点之间有长度为1的边直接相连. 求出从 1 号点 到 n 号点长度为k的路径的数目. 输入描述: ...

  5. [牛客OI测试赛2]F假的数学游戏(斯特灵公式)

    题意 输入一个整数X,求一个整数N,使得N!恰好大于$X^X$. Sol 考试的时候只会$O(n)$求$N!$的前缀和啊. 不过最后的结论挺好玩的 $n! \approx \sqrt{2 \pi n} ...

  6. 牛客OI测试赛2

    题目链接:https://www.nowcoder.com/acm/contest/185#question A.无序组数 暴力求出A和B的因子,注意二元组是无序的,因此还要考虑有些因子在A和B中都存 ...

  7. 【牛客OI赛制测试赛3】 毒瘤xor

    牛客OI赛制测试赛3 毒瘤xor 传送门 题面,水表者自重 Solution 前缀和简单题(挖坑待补) 代码实现 #include<stdio.h> #define int long lo ...

  8. 牛客OI赛制测试赛2(0906)

    牛客OI赛制测试赛2(0906) A :无序组数 题目描述 给出一个二元组(A,B) 求出无序二元组(a,b) 使得(a|A,b|B)的组数 无序意思就是(a,b)和(b,a) 算一组. 输入描述: ...

  9. 牛客OI月赛12-提高组题解

    牛客OI月赛12-提高组 当天晚上被\(loli\)要求去打了某高端oj部分原创的模拟赛,第二天看了牛客的题觉得非常清真,于是就去写了 不难发现现场写出\(260\text{pts}\)并不需要动脑子 ...

随机推荐

  1. TensorFlow六种激活函数

    TensorFlow六种激活函数 每个神经元都必须有激活函数.神经元提供了模拟复杂非线性数据集所必需的非线性特性.该函数取所有输入的加权和,进而生成一个输出信号.把它看作输入和输出之间的转换.使用适当 ...

  2. 微调BERT:序列级和令牌级应用程序

    微调BERT:序列级和令牌级应用程序 Fine-Tuning BERT for Sequence-Level and Token-Level Applications 为自然语言处理应用程序设计了不同 ...

  3. 电阻存储器为edge-AI提供了仿生架构

    电阻存储器为edge-AI提供了仿生架构 Resistive memories enable bio-inspired architectures for edge AI 近年来,脑启发计算领域的研究 ...

  4. 性能监控之常见 Java Heap Dump 方法

    一.前言 在本文中,我们总结下抓 Java dump 的几种不同方法. Java Heap Dump 是特定时刻 JVM 内存中所有对象的快照.它们对于解决内存泄漏问题和分析 Java 应用程序中的内 ...

  5. Pytorch Dataset和Dataloader 学习笔记(二)

    Pytorch Dataset & Dataloader Pytorch框架下的工具包中,提供了数据处理的两个重要接口,Dataset 和 Dataloader,能够方便的使用和加载自己的数据 ...

  6. 一起来聊聊 IP 地址、局域网、广域网、IPV4 和 IPV6

    背景 谁都知道 IP 地址是干嘛的,但是它出现的前因后果你真的知道吗? 我觉得很有必要重新复习下计算机网络基础知识,实在太太太重要了 本篇文章素材均来自:https://www.bilibili.co ...

  7. VScode如何设置模板字符串html标签自动补全

    在学习Vue的过程中,很多时候都需要用到模板字符串,但是里面的html标签一个字符一个字符的去敲未免也太麻烦了吧,其实我们可以通过设置来实现在模板字符串中按Tab键快速补全html标签. 1.在VSC ...

  8. 『无为则无心』Python基础 — 7、Python的变量

    目录 1.变量的定义 2.Python变量说明 3.Python中定义变量 (1)定义语法 (2)标识符定义规则 (3)内置关键字 (4)标识符命名习惯 4.使用变量 1.变量的定义 程序中,数据都是 ...

  9. Java通用树结构数据管理

    1.前言 ​ 树结构是一种较为常见的数据结构,如功能权限树.企业的组织结构图.行政区划结构图.家族谱.信令消息树等,都表现为树型数据结构. ​ 树结构数据的共性是树节点之间都有相互关系,对于一个节点对 ...

  10. 重新整理 .net core 实践篇————polly失败重试[三十四]

    前言 简单整理一下polly 重试. 正文 在开发程序中一般都有一个重试帮助类,那么polly同样有这个功能. polly 组件包: polly 功能包 polly.Extensions.Http 专 ...