当前位置: 首页 > wzjs >正文

网站开发的未来发展趋势最新的新闻 最新消息

网站开发的未来发展趋势,最新的新闻 最新消息,学什么技术挣两三万,wordpress 自动保存图片C. Phase Shift 题目: 思路: 好题,值得多看 这题我们看题目就能想到一个很显然的做法,那就是贪心地把每一个字母换成最前面的没使用过的字母 但是这样直接写是有问题的,因为题目说了最后要让所有的字母成一个换&…

C. Phase Shift

题目:

思路:

好题,值得多看

 这题我们看题目就能想到一个很显然的做法,那就是贪心地把每一个字母换成最前面的没使用过的字母

但是这样直接写是有问题的,因为题目说了最后要让所有的字母成一个换,比如如果是ba,如果我们换成ab,那么就会有一个a->b->a的环了,这显然不符合题意

所以对于每一个还未替换的字符,我们从a~z中选一个最先的最符合的字符,他要满足以下条件:

①.这个字符还没选过

②.这个字符不与现在这个字符相同

③.选完之后不能构成环,如果构成了,那只能是构成长度为26的环

确定好后按照题意模拟即可

代码:

#include <iostream>
#include <algorithm>
#include<cstring>
#include<cctype>
#include<string>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <memory>
using namespace std;
#define int long long
#define yes cout << "YES\n"
#define no cout << "NO\n"bool check(char a, char b,const map<char, char>& mp2)
{vector<int> vis(26, 0);map<char, char> mp = mp2;mp[a] = b;int hasc = 0;int ccnt = 0;while (mp[a]){if (vis[a - 'a']){hasc = true;break;}vis[a - 'a'] = 1;ccnt++;a = mp[a];}if (hasc && ccnt < 26){return false;}return true;
}void solve()
{int n;cin >> n;string s;cin >> s;map<char, char> mp;vector<bool> used(26, 0);for (int i = 0; i < n; i++){if (mp[s[i]]){continue;}else{for (int j = 0; j < 26; j++){int t = 'a' + j;if (used[j] || s[i] == t){continue;}if (check(s[i], t, mp)){used[j] = true;mp[s[i]] = t;break;}}}}for (int i = 0; i < n; i++){cout << mp[s[i]];}cout << endl;
}signed main()
{cin.tie(0)->sync_with_stdio(false);int t = 1;cin >> t;while (t--){solve();}return 0;
}


B. Playing with GCD

题目:

思路:

想难了,不过挺不错的

 一个显然的构造方法是 b[i] 取a[i] 和 a[i-1] 的lcm,因为我们要保证 gcd 恰好等于 a[i],所以最大只能取这个,同时 b[i] 与两个 a 都有关系,所以也只能这样取,否则如果是k*lcm,那么就会多个系数,这样最后可能就不会等于 a[i] 了

最后我们再检查一下 b[i] 是不是真的都符合即可

代码:

#include <iostream>
#include <algorithm>
#include<cstring>
#include<cctype>
#include<string>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <memory>
using namespace std;
#define int long long
#define yes cout << "YES\n"
#define no cout << "NO\n"int gcd(int a, int b)
{return !b ? a : gcd(b, a % b);
}int lcm(int a,int b)
{return a * b / gcd(a, b);
}void solve()
{int n;cin >> n;vector<int> a(n+2,1),b(n+2,1);for (int i = 1; i <= n+1; i++){if(i <= n)cin >> a[i];b[i] = lcm(a[i], a[i - 1]);}for (int i = 1; i <= n; i++){if (gcd(b[i],b[i+1]) != a[i]) {no;return;}}yes;
}signed main()
{cin.tie(0)->sync_with_stdio(false);int t = 1;cin >> t;while (t--){solve();}return 0;
}

C1. Good Subarrays (Easy Version)

题目:

思路:

双指针题

这道题由于求的是一个区间l~r,那么我们就可以来观察一下这个区间有没有什么特性

一个显然的特性是,如果l~r符合,那么l+1~r肯定也符合

代码:

#include <iostream>
#include <algorithm>
#include<cstring>
#include<cctype>
#include<string>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <memory>
using namespace std;
#define int long long
#define yes cout << "YES\n"
#define no cout << "NO\n"void solve()
{int n;cin >> n;vector<int> a(n);for (int i = 0; i < n; i++){cin >> a[i];}int l = 0, r = 0,res = 0;while (l < n){while (r < n && a[r] >= r-l+1){r++;}res += r - l;l++;}cout << res << endl;
}signed main()
{cin.tie(0)->sync_with_stdio(false);int t = 1;cin >> t;while (t--){solve();}return 0;
}


文章转载自:

http://LSbIDebg.jmbgL.cn
http://SlHHzUG2.jmbgL.cn
http://vH5FUsXb.jmbgL.cn
http://z9GH95R1.jmbgL.cn
http://bddk5w3j.jmbgL.cn
http://RSKh3iq0.jmbgL.cn
http://I2ytLJ4C.jmbgL.cn
http://3JtERcK3.jmbgL.cn
http://lAifC5dH.jmbgL.cn
http://ki1ul9Dq.jmbgL.cn
http://1ArkC8S8.jmbgL.cn
http://XgQTP5Ql.jmbgL.cn
http://7bfpppMl.jmbgL.cn
http://riK2w0s5.jmbgL.cn
http://3WLjRits.jmbgL.cn
http://N1ZZu0hG.jmbgL.cn
http://2SG5sEnI.jmbgL.cn
http://xm7UwkAC.jmbgL.cn
http://O9diKWTI.jmbgL.cn
http://fdvYEFRR.jmbgL.cn
http://uR2w2fRa.jmbgL.cn
http://veLJYTMJ.jmbgL.cn
http://u5hAhgeA.jmbgL.cn
http://Sr1tuWQb.jmbgL.cn
http://3yuFKv1O.jmbgL.cn
http://4qziyLhY.jmbgL.cn
http://KbXLBLag.jmbgL.cn
http://kIviUlzr.jmbgL.cn
http://a42wj84s.jmbgL.cn
http://1xNTDMsj.jmbgL.cn
http://www.dtcms.com/wzjs/611525.html

相关文章:

  • 云南商城网站建设网站域名如何使用
  • 如何建设网站安全建工行业建设标准网站
  • 以投资思维做网站柳江企业网站建设公司
  • 深圳网站备wordpress主题 时间轴
  • 西安市建设干部学校网站最新网络游戏排行榜2021前十名
  • 苏州建网站的公司一站式服务公司推广文案模板
  • 婚礼摄影作品网站ic外贸网站建设
  • 家居企业网站建设资讯网站制作北京网站建设公司哪家好
  • 网站推广公司卓立海创wordpress常用主题修改
  • 做网站是什么时候分页wordpress首页友情链接插件
  • 怎么建淘宝客网站贵州互联网公司
  • 南宁建站热搜页面设计在线
  • 经营一个网站要怎么做四川建设网电话号码是多少
  • 简易静态网站制作流程图wordpress安装dplayer
  • 郑州做网站排名杭州自适应网站建设
  • 创建平台网站下载链接如何在招聘网站上做薪酬统计
  • 视频网站代理响应式网站psd尺寸
  • 网站每天做100个外链网站开发用什么系统比较好?
  • 如何自己做免费网站中山网站建设文化价格
  • 万网如何建设购物网站长宁区网站建设网页
  • 公司做网站的费用产品设计培训
  • 九亭做网站公司建设部2018年工作要点网站
  • 深圳建站模板公司wordpress织梦扩展
  • 做原创的网站百度开户推广
  • 网站后台首页模板网站建设功能需求
  • 51制作视频mv网站磁力帝
  • asp网站500错误深圳建设工程交易服务网站
  • 网站域名301个人网站备案 备注
  • 织梦调用网站名称杭州物联网前十名公司
  • 南宁自助模板建站wordpress 广告管理