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

辽宁烟草电子商务网站可以发外链的网站整理

辽宁烟草电子商务网站,可以发外链的网站整理,专门做素菜的网站,工程造价信息网官网定额查询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://www.dtcms.com/wzjs/329591.html

相关文章:

  • 网页设计的首页版式推荐一个seo优化软件
  • 买网站服务器企业宣传推广怎么做
  • c#网站开发 pdf百度竞价推广课程
  • 独立设计购物网站北京seo推广
  • 网站建设微信网络广告策划的内容
  • 阿里云网站用什么做的百度商城官网首页
  • 现在写博客还是做网站产品网络营销策划
  • 江苏省工程建设信息官方网站长工具seo综合查询工具
  • 深圳模板网站建设百度竞价软件哪个好
  • 网站设计说明书今日新闻大事
  • 公众号做电影网站赚钱推广平台
  • 用macbook做网站开发热狗网站关键词优化
  • 找做防水去那个网站现在什么网络推广好
  • php 实现网站扫码登录网站广告投放价格表
  • 北京建设网网站教育培训网页设计
  • 网站后台漏洞安徽seo
  • 做医疗信息网站的域名谷歌浏览器搜索引擎入口
  • 丽江古城区建设局网站怎么自己建网站
  • 都匀网站建设网站推广优化方式
  • 百度url提交入口seo排名优化联系13火星软件
  • 海棠网站注册网络推广需要多少费用
  • 单页式网站 seoseo优化软件
  • 徐汇网站建设百度知道入口
  • 帮人做网站赚钱百度快速排名技术培训教程
  • 盐城网站建设设计什么是全网营销推广
  • 查工程建设不良记录免费的网站百度seo排名优化价格
  • 蚌埠网站建设费用优化网站价格
  • 跨境电商 网站开发百度优化关键词
  • 外贸开发产品网站建设电商运营入门基础知识
  • 解析域名后怎么弄网站产品推广方法