A 回文括号序列计数,找规律

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e6+10;
const int mod = 998244353;int main(){ios::sync_with_stdio(false);int T;  cin>>T;while(T--){LL n;  cin>>n;if(n==0){cout<<"1\n"; continue;}if(n>=1){cout<<"0\n"; continue;}}return 0;
}

C 末三位,快速幂

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e6+10;
const int mod = 1000;LL mpow(LL a, LL x) {if(x==0)return 1;LL t = mpow(a, x>>1);if(x%2==0)return t*t%mod;return t*t%mod*a%mod;
}int main(){ios::sync_with_stdio(false);LL n;while(cin>>n){if(n==0){cout<<"001\n";continue;}if(n==1){cout<<"005\n";continue;}if(n==2){cout<<"025\n";continue;}cout<<mpow(5,n)<<"\n";}return 0;
}

D 划数,贪心模拟

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 2e5+10;
const int mod = 1000;
int main(){ios::sync_with_stdio(false);LL n, cnt; while(cin>>n>>cnt){if(n==2){LL x, y;  cin>>x>>y;if(x==cnt)cout<<y<<"\n";else cout<<x<<"\n";continue;}LL sum = 0, ok = 1;for(int i = 1; i <= n; i++){LL x;  cin>>x;if(x==cnt && ok==1){ok = 0;continue;}else{sum += x;sum %= 11;}}cout<<sum<<"\n";}return 0;
}

F 组合数问题,贪心找规律

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 5e5+10;
const int mod = 998244353;LL mpow(LL a, LL x) {if(x==0)return 1;LL t = mpow(a, x>>1);if(x%2==0)return t*t%mod;return t*t%mod*a%mod;
}int main(){ios::sync_with_stdio(false);LL n;  cin>>n;LL k = n/4, ans;if(k%2==1)ans = (mpow(2,n-2)-2*mpow(4,k-1)%mod+mod)%mod;else ans = mpow(2,n-2)+2*mpow(4,k-1)%mod;ans %= mod;cout<<ans<<"\n";return 0;
}/*
121212121248
7212
99213
2016
14
4096
15
825616
1651217
32896
18
6553620 5
262144 261632 -512 -2*4^424 6
4194304 4196352 +2048 +2*4^528 7
67108864 67100672 -8192 -2*4^632 8
75497471 75530239 +32768123232
*/

G 机器人,贪心排序

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;inline void print(__int128 x){if(x < 0){ putchar('-'); x = -x; }if(x > 9)print(x/10);putchar(x%10+'0');
}const int maxn = 1010;
int n, x, a[maxn], b[maxn], r[maxn];
bool cmp(int x, int y){//return a[x]*b[x]>a[y]*b[y];return b[x]*(a[y]-1)>b[y]*(a[x]-1);//return a[x]*a[x]+b[x]<a[y]*a[y]+b[y];//if(a[x]*b[y]!=a[y]*b[x])return (a[x]*b[y]<a[y]*b[x]);//return a[x]>a[y];//return a[x]+b[y]<a[y]+b[x];//if(a[x] != a[y])return a[x]>a[y];//return b[x]>b[y];//if(b[x]!=b[y])return b[x]>b[y];//return a[x]<a[y];
}int main(){cin>>n>>x;for(int i = 1; i <= n; i++)cin>>a[i]>>b[i];for(int i = 1; i <= n; i++)r[i] = i;sort(r+1,r+n+1,cmp);__int128 ans = x;for(int i = 1; i <= n; i++){ans = ans*a[r[i]]+b[r[i]];}//cout<<ans<<'\n';print(ans);return 0;
}

I 贪吃蛇,BFS

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 110+10;
const int mod = 1000;int sx, sy, tx, ty;
char a[maxn][maxn];struct node{int x,y, step=0;};
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int vis[maxn][maxn];int main(){ios::sync_with_stdio(false);int n, m; cin>>n>>m;cin>>sx>>sy>>tx>>ty;for(int i = 1; i <= n; i++){for(int j = 1; j <= m; j++){cin>>a[i][j];}}queue<node>q;q.push({sx,sy,0});vis[sx][sy] = 1;int ans = 1e9+10, ok = 1;while(q.size()){node t = q.front(); q.pop();if(t.x==tx && t.y==ty){ans = min(ans,t.step);ok = 0;}vis[t.x][t.y] = 1;for(int i = 0; i < 4; i++){int nx = t.x+dx[i], ny = t.y+dy[i];if(nx<1||nx>n||ny<1||ny>m)continue;if(a[nx][ny]=='#' || vis[nx][ny]==1)continue;q.push({nx,ny,t.step+1});vis[nx][ny]=1;}}if(ok==0)cout<<ans*100<<"\n";else cout<<"-1\n";/*for(int i = 1; i <= n; i++){for(int j = 1; j <= m; j++)cout<<a[i][j]<<" ";cout<<"\n";}*/return 0;
}

J 天空之城,最小生成树

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 2e5+10;
const int mod = 1000;struct Edge{int u, v, w;Edge(int u=0, int v=0, int w=0):u(u),v(v),w(w){}bool operator < (Edge b)const{return w<b.w;}
};int fa[maxn];
void init(int n){for(int i=1;i<=n;i++)fa[i]=i;}
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
void merge(int x,int y){x=find(x);y=find(y);if(x!=y)fa[x]=y;}int main(){ios::sync_with_stdio(false);int n, q;while(cin>>n>>q){map<string,int>ma; int tot=0;vector<Edge>e;string s;  cin>>s;tot++; ma[s] = tot;for(int i =1; i <= q; i++){string u, v; int uu,vv,w;cin>>u>>v>>w;if(ma.count(u))uu = ma[u];else {uu = ++tot; ma[u]=uu;}if(ma.count(v))vv = ma[v];else {vv = ++tot; ma[v]=vv;}e.push_back({uu,vv,w});}sort(e.begin(),e.end());LL ans = 0;init(n);int cnt = 1;for(int i = 0; i < e.size(); i++){int u = e[i].u, v = e[i].v;if(find(u) != find(v)){merge(u,v);ans += e[i].w;cnt++;}}if(cnt==n)cout<<ans<<"\n";else cout<<"No!\n";}return 0;
}

2021牛客寒假算法基础集训营6,签到题ACDFGIJ相关推荐

  1. 2022牛客寒假算法基础集训营6 签到题5题(附基础集训营4-6签到题总结)

    1.I-A+B问题 模拟,类似于高精度,竖式运算 #include<bits/stdc++.h> using namespace std; typedef long long LL; in ...

  2. 2022牛客寒假算法基础集训营3 签到题7题(附基础集训营1-3签到题总结)

    1.A-智乃的Hello XXXX 签到 #include<bits/stdc++.h> using namespace std; int main(){cout<<" ...

  3. 2022牛客寒假算法基础集训营4 签到题7题

    1.E-真假签到题 不难发现,或者随便枚举一下,可以得到f(n)=n的结论 #include<bits/stdc++.h> typedef long long LL; using name ...

  4. 2022牛客寒假算法基础集训营2 签到题7题

    1.C 小沙的杀球 如果你能够杀球但不杀球,虽然回复了体力,但你后续可能会没有机会继续杀球,并且杀球次数相同,那么回复的体力是相同的,所以在同等条件下,我们应该尽可能多的杀球. 不开long long ...

  5. 2022牛客寒假算法基础集训营1 签到题7题

    1.L.牛牛学走路 恭喜你 签到成功 #include<bits/stdc++.h> using namespace std; int main(){int T; cin>>T ...

  6. 2021牛客寒假算法基础集训营1 J 一群小青蛙呱蹦呱蹦呱

    今天的比赛没打( 睡午觉去了,今天太累了 晚上来看看题 2021牛客寒假算法基础集训营1 J 一群小青蛙呱蹦呱蹦呱 题目传送门 板子题( 我们知道由唯一分解定理得,若 n=p1α1×p2α2×p3α3 ...

  7. 【解题报告】2021牛客寒假算法基础集训营4

    [解题报告]2021牛客寒假算法基础集训营4 前面的话 A :九峰与签到题 | 模拟 (签到题) B: 武辰延的字符串 | exKMP D :温澈滢的狗狗 | 二分 E: 九峰与子序列 | d p d ...

  8. 2021牛客寒假算法基础集训营1

    2021牛客寒假算法基础集训营1 A. 串(线性DP) B. 括号(构造) E.三棱锥之刻(几何) F. 对答案一时爽(签到) I. 限制不互素对的排列(构造) J. 一群小青蛙呱蹦呱蹦呱 A. 串( ...

  9. 2021牛客寒假算法基础集训营2 D.牛牛与整除分块

    2021牛客寒假算法基础集训营2 D.牛牛与整除分块 题目链接 题目描述 整除分块,又称数论分块.是数论算法中的重要技巧,你可以在各种需要枚举因子的连续求和类问题中见到它的身影.如杜教筛,莫比乌斯反演 ...

  10. 2021牛客寒假算法基础集训营5 B.比武招亲(上)

    2021牛客寒假算法基础集训营5 B.比武招亲(上) 题目链接 题目描述 众所周知,天姐姐只喜欢天下最聪明的人,为了找到这样的人,她决定比武招亲! 只见天姐姐在榜上留下了这样一道问题,谁做出来了就可以 ...

最新文章

  1. flannel原理初探针对0.1.0版本
  2. RocketMQ生产者流程篇
  3. 网络设备中的linux,理解linux虚拟网络设备veth
  4. alertdialog.builder 自定义弹窗
  5. [HAOI2006]均分数据
  6. bzoj2424 订货
  7. 坚持,这两个字非常重要!
  8. 把第三方jar包放入本地私服
  9. c语言程序设计二级考试哪些题型,计算机二级考试题型及分值
  10. php 可选表格,PHP_表格标记,  ■ 表格标记 TABLE - phpStudy
  11. vb 开机到现在的时间
  12. VMWare网络连接方式与设置
  13. Cakephp 创建无模型的Controller
  14. python中引用javascript代码块
  15. ubuntu大小写切换键的使用
  16. 第一章: 利用神经网络识别手写数字
  17. matlab基础与符号计算,Chapter 7. MATLAB符号计算基础
  18. 2017CCCC天梯赛决赛 赛后总结
  19. 基于微信小程序付费自习室系统(微信小程序毕业设计)
  20. Android蓝牙开发——经典蓝牙的连接

热门文章

  1. 学习 nltk —— TF-IDF
  2. R 语言学习(二)—— 向量
  3. 氢离子浓度指数(ph值)
  4. 趣学 C 语言(九)—— 复杂指针解析
  5. C++基础::文件流(二)
  6. python怎么读写文件-手机上怎么写pythonPython文件读写详解及设置文件的字符编码...
  7. 学python买什么书-19年学习Python有什么好的书籍推荐吗?
  8. 下载python教程-零基础Python教程全集下载.pdf
  9. python基础教程是什么-Python基础教程_Python入门知识
  10. python最适合做什么-总算明了python适合做什么