目录

  • 冰狱寒岚【简单】
  • 光之屏障【简单】
  • 寒潭烟光【简单】
  • 金蛇狂舞【bfs】
  • 暗灭侵蚀【模拟】
  • 火凤燎原【思维】

冰狱寒岚【简单】


https://ac.nowcoder.com/acm/contest/26561/A
就是打表即可,然后查询即可。

#include<bits/stdc++.h>
using namespace std;
int n,m,t;
vector<int>ve;
int main(void)
{for(int i=0;i<1024;i++) ve.push_back(i);for(int i=1024;i>0;i--) ve.push_back(-i);cin>>n;while(n--){int x;  cin>>x;cout<<ve[x%2048]<<" ";}return 0;
}

光之屏障【简单】

https://ac.nowcoder.com/acm/contest/26561/B
打表,二分找答案。

#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
vector<LL>ve;
int main(void)
{int t; cin>>t;for(int i=0;i<=31;i++) ve.push_back(pow(2,i));while(t--){LL a,b; cin>>a>>b;int l=lower_bound(ve.begin(),ve.end(),a)-ve.begin();int r=upper_bound(ve.begin(),ve.end(),b)-ve.begin();if(l>=r) puts("-1");else cout<<ve[l]<<endl;}return 0;
}

想复杂了,数据很小,其实直接模拟即可。

#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
vector<LL>ve;
int main(void)
{int t; cin>>t;while(t--){LL a,b; cin>>a>>b;LL sum=1;while(sum<a) sum*=2;if(sum>=a&&sum<=b) cout<<sum<<endl;else cout<<-1<<endl;}return 0;
}

寒潭烟光【简单】


https://ac.nowcoder.com/acm/contest/26561/C
他这个是,前缀和数组的平均值,加一个x,总和加了(n+1)*x

#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
int main(void)
{int t; cin>>t;while(t--){LL n,f,x0; cin>>n>>f>>x0;LL sum=(n*(f+x0)+x0)/(n+1);cout<<sum<<endl;}return 0;
}

金蛇狂舞【bfs】


https://ac.nowcoder.com/acm/contest/26561/D
bfs即可,通过数据范围可以知道阶乘一般不会太大,因为太大显然是无意义的。

#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
const int N=15;
LL f[N];
LL bfs(int x,int y)
{   unordered_map<LL,LL>mp; mp[x]=1;queue<pair<LL,LL>>q; q.push({x,0});while(q.size()){auto temp=q.front(); q.pop();int u=temp.first,step=temp.second;if(step>7) continue;if(u==y) return step;LL a[3]={0};a[1]=ceil(sqrt(u*1.0)),a[2]=floor(sqrt(u*1.0));if(u>15) a[0]=0;else a[0]=f[u];for(int i=0;i<3;i++){if(!i&&u>=N) continue;if(!mp[a[i]]) {q.push({a[i],step+1});mp[a[i]]++;}}}return -1;
}
int main(void)
{f[0]=1;for(int i=1;i<N;i++) f[i]=f[i-1]*i;LL t; cin>>t;while(t--){LL x,y; cin>>x>>y;cout<<bfs(x,y)<<endl;}return 0;
}

暗灭侵蚀【模拟】


https://ac.nowcoder.com/acm/contest/26561/E

#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
int main(void)
{LL t; cin>>t;while(t--){LL a[3],n;priority_queue<LL>heap;for(int i=0;i<3;i++) cin>>a[i],heap.push(a[i]);cin>>n;int cnt=0;while(1){for(int i=0;i<3;i++) a[i]=heap.top(),heap.pop();if(a[0]>=n) break;a[2]=a[0]*2-a[2];for(int i=0;i<3;i++) heap.push(a[i]);cnt++;}cout<<cnt<<endl;}return 0;
}

火凤燎原【思维】


https://ac.nowcoder.com/acm/contest/26561/F
就是,统计每个点的度,然后枚举每一个点计算其贡献。
根据题意可知,只有度大于等于3才是蒲公英。

#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
const int N=1e5+10;
int d[N],t,n;
int main(void)
{cin>>t;while(t--){cin>>n;for(int i=0;i<=n;i++) d[i]=0;for(int i=1;i<n;i++) {int a,b; scanf("%d%d",&a,&b);d[a]++,d[b]++;}LL ans=0;for(int i=1;i<=n;i++)//枚举每一个点if(d[i]>=3) ans+=n-1-d[i];printf("%lld\n",ans);}return 0;
}

牛客月赛42题解【完结】相关推荐

  1. 牛客挑战赛42 A.小睿睿的数列

    牛客挑战赛42 A.小睿睿的数列 题目链接 题目描述 小睿睿给了你一个长度为n的数列,他想问你该数列中满足条件(区间内存在某个数是区间内所有数的公因数)的最长区间有多少个 输入描述: 第一行 111 ...

  2. 牛客月赛60 F.被抓住的小竹(数学推式子)

    牛客月赛60 F.被抓住的小竹(数学&推式子) 考虑枚举每个区间的贡献. 每个区间内所有的数都作为 x x x一次时的贡献和. 因为要求区间内 ≥ x \ge x ≥x数个数, 那么区间内的数 ...

  3. 牛客练习赛24题解(搜索,DP)

    A题,C题不讲,基础题(但是我要抨击一下这次比赛,卡cin,cout,卡的太狠了,根本就不让过的那种,QAQ) 链接:https://www.nowcoder.com/acm/contest/157/ ...

  4. 牛客练习赛29 题解

    牛客练习赛29 A. 可持久化动态图上树状数组维护01背包 题解 这题跟标题没有任何关系- 贪心的使得负数删除的时候下标尽可能大,然后正数的时候下标尽可能小. 观察到每个数下标最大的时候就是它的初始下 ...

  5. 牛客练习赛94F题解

    链接:登录-专业IT笔试面试备考平台_牛客网 令sec(x)表示mex为x的最小区间,假设当前插入到t,只需维护x = 1 ~ t的sec(x)的左右端点位置即可(这里端点位置定义为在当前已经存在的数 ...

  6. 牛客题库 题解 | #[NOIP2017]图书管理员#

    链接:#[NOIP2017]图书管理员# 题目牛客网是互联网求职神器,C++.Java.前端.产品.运营技能学习/备考/求职题库,在线进行百度阿里腾讯网易等互联网名企笔试面试模拟考试练习,和牛人一起讨 ...

  7. 山楂(牛客月赛45 )

    山楂 链接:https://ac.nowcoder.com/acm/contest/11222/C 来源:牛客网 众所周知,清楚姐姐最近迷上了一个老年游戏"山楂串"(点进去可以玩) ...

  8. 牛客月赛 44 补题题解

    目录 A-深渊水妖 B-顽皮恶魔 C-绝命沙虫 D-丛林木马 E-变异蛮牛 F-幽暗统领 总结 大佬题解 记录第二次比赛的题解 没想到学了一年半算法之后,还有一场比赛会爆0,打击很大,继续努力 比赛传 ...

  9. Array of Discord牛客网竞赛题解

    题目描述 Once upon a time, high up on Mount Olympus, it came to pass that the gods held a competition to ...

最新文章

  1. JavaScript 中 Object ,Prototype 相关的属性和方法
  2. php 定义数字int,php中的int参数
  3. 使用 Edit + MASM 5.0 编译器 + Linker 连接器
  4. 一次处理ORA-06512的经验
  5. Java的Comparator排序(升序降序)理解
  6. 搜索关键字字符串NSSCanner:scanString()详解
  7. WebService之Java原生态支持(二)
  8. Bootstrap 条纹进度条
  9. 化工企业数据分析中心项目之采购模块分析
  10. pyserial串口通信之红外线测距模块
  11. Java SE 007 流程控制语句 续
  12. 由JavaScript版迷宫游戏引出Java版迷宫地图生成器
  13. 使用mybaisplus时使用LambdaQueryWrapper进行条件查询发生evaluating expression异常处理
  14. android 监听 短信,Android短信验证码监听解决onChange多次调用的方法
  15. 使用Oracle数据库的一些小记录 1
  16. java fx svg 图像 缩放 控件,支持调整SVG图像大小!Aspose.Imaging v19.11新功能示例演示!...
  17. Android Camera开发系列:设置对焦模式模式
  18. Java-IO-字符流
  19. Linux下的Makefile编写与优化
  20. SSL peer shut down incorrectly 问题处理方法

热门文章

  1. ubuntu160.4+anaconda3 +tensorflow1.140 +keras2.2.5安装
  2. try-catch-finally 与返回值的修改
  3. HTMLTestRunner加入logging输出
  4. JavaWeb学习总结(六)—HttpServletResponse
  5. Spring基础知识及入门
  6. 【BZOJ1623】 [Usaco2008 Open]Cow Cars 奶牛飞车 贪心
  7. Canvas 属性,方法
  8. mac 下launchpad超级慢的问题
  9. 在ubuntu上安装,使用MQTT Mosquitto
  10. STM32 SPI难点浅析