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

网上制作网站加盟网络营销推广公司

网上制作网站,加盟网络营销推广公司,怎么查网站在哪备案,注册安全工程师报考时间2023C. Dining Hall 题目: 思路: 题目不难,但是读题困难了 题意缩减一下就是1是社牛,只要离得近并且有位置,那就直接坐,0是社恐,必须要离得近的同时这一桌都没人才坐 那我们就可以分析出来&#x…

C. Dining Hall

题目:

 

思路:

题目不难,但是读题困难了

题意缩减一下就是1是社牛,只要离得近并且有位置,那就直接坐,0是社恐,必须要离得近的同时这一桌都没人才坐

那我们就可以分析出来,0只可能坐到一个桌子的左下角,而1可以随便坐,那我们按题意模拟即可

由于n最多50000,那么我们最多只需要计算到 n*3 的坐标即可(观察图中例子可知其坐标是3倍的关系递增)

那么如何模拟呢?我们可以用set来储存桌子,我们可以将坐标和距离打包在一个pair中,这样自动排序的时候就会按距离先排了,如果距离相同再按x小的排

特别的,由于0只坐左下角,为了方便我们可以给他专门开个set存左下角的位置

注意,每次使用后记得删除

代码:

#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;int len = 3 * n;set<pair<int, pair<int, int>>> s0, s1;pair<int, pair<int, int>> nowpos;for (int x = 0; x <= sqrt(len); x++){for (int y = 0; y <= sqrt(len); y++){int dis = 3 * (x + y) + 2;int newx = 3 * x + 1;int newy = 3 * y + 1;s0.insert({ dis,{newx,newy} });s1.insert({ dis,{newx,newy} });s1.insert({ dis + 1,{newx,newy + 1} });s1.insert({ dis + 1,{newx + 1,newy} });s1.insert({ dis + 4,{newx + 1,newy + 1} });}}vector<int> t(n);for (int i = 0; i < n; i++){cin >> t[i];}for (int i = 0; i < n; i++){if (t[i])nowpos = *s1.begin();elsenowpos = *s0.begin();cout << nowpos.second.first << " " << nowpos.second.second << endl;s0.erase(nowpos);s1.erase(nowpos);}
}signed main()
{cin.tie(0)->sync_with_stdio(false);int t = 1;cin >> t;while (t--){solve();}return 0;
}

D. Simple Permutation

题目:

思路:

喜闻乐见的构造题,脑电波对上了,但么写出

题目让我们构造出一个排列使得满足对于 c 集合存在至少 [n/3] - 1个元素,其中 c[i] 代表的是前 i 个元素的和除以 i ,即 c[i] = Sum(p[1]~p[i]) / i

这题有两个方法,先说我一开始想的

①.我们观察样例可以知道,我们要构造出素素,那么肯定是往小的素数上构造,因为越往后素数越大,离得也越远,那我们肯定要构造出一个这样的数列 c ,其形式如 2 3 3 3 5 5 5 7 7 7...

比如最后一个样例是 2 1 3 4 5,那么如果我们后面要构造的话肯定只能构造5了,因为就算我们选的数是6,我们最小只能获得4,这显然不利于我们构造,所以我们就应该看看能不能构造出5来,显然是可以的,但是前提是我们能取到,但是方法我感觉有点复杂了。。。

②.如果我们观察仔细的话,我们可以观察到题目的要求是 n/3 ,我们来想一想这有什么特性吗?

欸,我们可以发现,如果我们把排列分成 3 等份,那么我只要在中间这等分里找到一个素数 p,那么肯定能在左右两边都拿出两个数来组成素数 p 的两倍,比如如果我们选7,那么我们就可以选6 8构成 7 6 8,这样就有两个素数了,也就是说我们可以将两个数变成一个素数

那么我们两侧都有n/3个数,那么我们起码能构造出n/3个素数,只要我们在中间任选一个素数,这一定是可以构造出来的

代码:

#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 isp[100005];void prework()
{isp[0] = isp[1] = 0;for (int i = 2; i <= 100000; i++){isp[i] = 1;for (int j = 2; j <= sqrt(i); j++){if (i != j && i % j == 0)isp[i] = 0;}}
}void solve()
{int n;cin >> n;int p = 0;for (int i = n/3; i <= n*2/3; i++){if (isp[i]){p = i;break;}}if (p == 0){for (int i = 1; i <= n; i++)cout << i << " ";cout << endl;}else{cout << p << " ";int l = p - 1, r = p + 1;while (l || r <= n){if (l) {cout << l << " ";l--;}if (r <= n){cout << r << " ";r++;}}cout << endl;}
}signed main()
{prework();cin.tie(0)->sync_with_stdio(false);int t = 1;cin >> t;while (t--){solve();}return 0;
}

http://www.dtcms.com/wzjs/81719.html

相关文章:

  • 在工商局网站如果做注销公告网站搜索优化
  • 做网站的公司 洛阳一站式软文发布推广平台
  • 利用网站源代码建立网站数字营销策划
  • 大型网站设计首页实例搜索大全引擎地址
  • 萍乡网站建设哪家好哦嘉定区整站seo十大排名
  • 网站建设优化话术德阳seo
  • 建设银行社保卡网站在哪搜索引擎优化的基本方法
  • 沧州网站制作石家庄seo按天扣费
  • 深圳做网站比较好的公司关键词竞价排名是什么意思
  • 邢台移动网站建设报价html简单网页设计作品
  • 价格低的跑车杭州seo优化公司
  • 青岛网络平台宁波优化seo是什么
  • 简述网站开发具体流程图优化用户体验
  • 网站建设规划设计公司百度指数免费添加
  • 下单的网站建设教程新发布的新闻
  • 沈阳企业网站排名优化seo有哪些作用
  • 石家庄站内换乘示意图百度快速收录账号购买
  • 网站建设免费建站优化设计四年级上册语文答案
  • 永州市建设局网站营销型企业网站案例
  • 别人的抖音网站是怎么做的百度站长平台有哪些功能
  • 怎么用html5做自适应网站申京效率值联盟第一
  • b2b电商网站开发免费创建网站平台
  • 推广型网站制作公司百度app下载最新版
  • 宠物网站建设方案书怎样创建自己的网站
  • 织梦做中英文网站seo网站推广优化就找微源优化
  • 创意网站 模板google关键词挖掘工具
  • 玄武营销型网站制作厂家软文推广名词解释
  • 如何用电子邮箱做网站google应用商店
  • 网站后台图片做链接怎么去推广自己的店铺
  • 做最好的在线中文绅士本子阅读网站中国国家数据统计网