题解——牛客网OI赛制测试赛2
T1
规律题
考虑先全部选中再去重即可
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int barrel[]={};
int main(){
int T;
scanf("%d",&T);
for(int tt=;tt<=T;tt++){
int cnta=,cntb=,cnt=,ans=;
int a,b;
scanf("%d %d",&a,&b);
for(int i=;i<=sqrt(a);i++){
if(a%i==){
if(i!=a/i){
barrel[i]=tt;
barrel[a/i]=tt;
cnta+=;
}
else{
barrel[i]=tt;
cnta+=;
}
}
}
// printf("%d\n",cnta);
for(int i=;i<=sqrt(b);i++){
if(b%i==){
if(i!=b/i){
cntb+=;
}
else{
cntb+=;
}
if(i!=b/i){
if(barrel[i]==tt){
cnt++;}
if(barrel[b/i]==tt){
cnt++;}}
else{
if(barrel[i]==tt){
cnt++;}
}
}
}
// printf("%d\n",cnt);
ans+=cnta*cntb-(cnt)*(cnt-)/;
printf("%d\n",ans);
}
return ;
}
T2
科技题
考试的时候完全不知道有传递闭包的黑科技
可以解决比如\( a \) 和\( b \)是否联通
\( a\)到\( b \)有多少条长度为k的路径的问题
有Floyd和矩阵快速幂两种解法
比较有趣
然后记得开long long
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#define int long long
using namespace std;
int n,k;
struct Matrix{
static const int MAXN = ;
int alpha[MAXN][MAXN];
int n,m;
void init2(void){
for(int i=;i<MAXN;i++)
for(int j=;j<MAXN;j++)
alpha[i][j]=;
n=m=;
}
void init(int x){
for(int i=;i<=x;i++)
alpha[i][i]=;
n=m=x;
}
Matrix operator *(Matrix b){
Matrix tmp;
tmp.init2();
for(int i=;i<=n;i++)
for(int j=;j<=b.m;j++)
for(int k=;k<=m;k++)
tmp.alpha[i][j]+=alpha[i][k]*b.alpha[k][j];
tmp.n=n;
tmp.m=b.m;
return tmp;
}
};
Matrix pow(Matrix a,int p){
Matrix ans;
ans.init2();
ans.init(a.n);
while(p){
if(p&)
ans=ans*a;
a=a*a;
p>>=;
}
return ans;
}
signed main(){
scanf("%lld %lld",&n,&k);
Matrix a;
a.init2();
a.m=a.n=n;
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
scanf("%lld",&a.alpha[i][j]);
Matrix b=pow(a,k);
printf("%lld",b.alpha[][n]);
return ;
}
T3
单调栈经典应用,随手一码即可
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <stack>
using namespace std;
struct Node{
int pos,x;
};
stack<Node> S;
int a[],n,b[];
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
for(int i=;i<=n;i++){
while((!S.empty())&&a[i]>S.top().x){
b[S.top().pos]=i;
S.pop();
}
S.push(Node{i,a[i]});
}
while(!S.empty()){
b[S.top().pos]=;
S.pop();
}
for(int i=;i<=n;i++)
printf("%d ",b[i]);
return ;
}
T4
瞪眼打表出轨率OR玄学证明一下?
也是规律题
记得long long
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#define int long long
using namespace std;
int n;
signed main(){
scanf("%lld",&n);
if(n==)
printf("");
else
printf("%lld",(int)sqrt(n) );
return ;
}
T5
结论题
扫一遍统计一下有多少不匹配就可以了
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int l=,rno=,n;
bool get(void){
char c=getchar();
while(c!='('&&c!=')')
c=getchar();
if(c=='(')
return true;
else
return false;
}
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
if(get()){
l+=;
}
else{
if(l)
l--;
else
rno++;
}
}
if(rno==)
printf("");
else
printf("%d",(rno%)?(rno/+):(rno/));
return ;
}
T6
貌似提交答案?
手动二分+Ruby求阶乘打表qwq
还打错了一个
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;
long long n;
int main(){
cin>>n;
if(n==)
printf("10\n");
if(n==)
printf("94\n");
if(n==)
printf("892\n");
if(n==)
printf("8640\n");
if(n==)
printf("84657\n");
if(n==)
printf("834966\n");
if(n==)
printf("8267019\n");
if(n==)
printf("82052137\n");
if(n==)
printf("815725636\n");
if(n==)
printf("8118965902\n");
return ;
}
题解——牛客网OI赛制测试赛2的更多相关文章
- 【牛客OI赛制测试赛3】 毒瘤xor
牛客OI赛制测试赛3 毒瘤xor 传送门 题面,水表者自重 Solution 前缀和简单题(挖坑待补) 代码实现 #include<stdio.h> #define int long lo ...
- 牛客OI赛制测试赛2(0906)
牛客OI赛制测试赛2(0906) A :无序组数 题目描述 给出一个二元组(A,B) 求出无序二元组(a,b) 使得(a|A,b|B)的组数 无序意思就是(a,b)和(b,a) 算一组. 输入描述: ...
- 牛客OI赛制测试赛2
A题: https://www.nowcoder.com/acm/contest/185/A 链接:https://www.nowcoder.com/acm/contest/185/A来源:牛客网 题 ...
- 8.30 牛客OI赛制测试赛1 F题 子序列
题目描述 给出一个长度为n的序列,你需要计算出所有长度为k的子序列中,除最大最小数之外所有数的乘积相乘的结果 输入描述: 第一行一个整数T,表示数据组数.对于每组数据,第一行两个整数N,k,含义如题所 ...
- C数列下标 牛客OI赛制测试赛2
链接:https://www.nowcoder.com/acm/contest/185/C来源:牛客网 给出一个数列 A,求出一个数列B. 其中Bi 表示 数列A中 Ai 右边第一个比 Ai 大的 ...
- 牛客OI赛制测试赛2 D 星光晚餐
链接:https://www.nowcoder.com/acm/contest/185/D来源:牛客网 题目描述 Johnson和Nancy要在星光下吃晚餐.这是一件很浪漫的事情. 为了增加星光晚餐那 ...
- 牛客OI赛制测试赛2 C 数组下标
链接:https://www.nowcoder.com/acm/contest/185/C来源:牛客网 题目描述 给出一个数列 A,求出一个数列B. 其中Bi 表示 数列A中 Ai 右边第一个比 ...
- 牛客OI赛制测试赛2 A 无序组数
链接:https://www.nowcoder.com/acm/contest/185/A来源:牛客网 题目描述 给出一个二元组(A,B) 求出无序二元组(a,b) 使得(a|A,b|B)的组数 无序 ...
- 题解——牛客网Wannafly挑战赛23 B-游戏 (SG函数)
前言 比赛的时候没学过SG函数的蒟蒻以为是道结论题,但是不是QwQ 和dummyummy巨佬一起推了快三个小时的规律 最后去问了真正的巨佬__stdcall __stdcall面带微笑的告诉我们,这是 ...
随机推荐
- html5-label标签
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- python - 6. Defining Functions
From:http://interactivepython.org/courselib/static/pythonds/Introduction/DefiningFunctions.html Defi ...
- jQuery样式--css(name|pro|[,val|fn])
css(name|pro|[,val|fn]) 概述 访问匹配元素的样式属性 参数 name 要访问的属性名称 name 一个或多个CSS属性组成的一个数组 properties 要设置为样式属 ...
- codeforces 979C Kuro and Walking Route
题意: 给出一棵树,其中有两个点,x和y,限制走了x之后的路径上不能有y,问可以走的路径(u,v)有多少条,(u,v)和(v,u)考虑为两条不同的路径. 思路: 简单树形dp,dfs统计在x到y路径( ...
- 【Hive学习之三】Hive 函数
环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 hadoop-3.1.1 apache-hive-3.1.1 ...
- 【Hadoop学习之七】Hadoop YARN
环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 hadoop-3.1.1 YARN: ...
- 加密对象到locastorage / 从 locastorage解密对象
var obj={name:"致远",age:21,address:"江西上饶XXXX",hobby:"看书,编程"};//用中文 记得加e ...
- 75.Java异常处理机制-自定义异常
package testDate; //自定义异常 public class MyException extends Exception{ public MyException(){ } public ...
- [trick] 玩弄svn的目录结构
今天在使用svn进行版本管理时出现了一个小问题: 原本在s目录下有一个c目录,不知为何被删除了,而svn st命令并没有认为它消失,svn up命令也无法下载回来: 从另一个地方拷贝过来一个c,svn ...
- Zynq ZC706 传统方式移植Linux -- 编译u-boot
我用的是zc706不是zed 基本思路是: 1.安装交叉编译工具(见 https://www.cnblogs.com/idyllcheung/p/10532654.html ) 2.下载xilinx ...