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

婚礼案例网站有了主机如何做网站

婚礼案例网站,有了主机如何做网站,中秋节ppt免费模板下载,拓者设计吧室内设计官网案例A. One and Two给出一个数组&#xff0c;该数组仅由1和2组成&#xff0c;问是否有最小的k使得k位置的前缀积和后缀积相等。思路&#xff1a;计算2个数的前缀和即可&#xff0c;遍历判断。AC Code&#xff1a;#include <bits/stdc.h>typedef long long ll; const int N 1…

A. One and Two

给出一个数组,该数组仅由1和2组成,问是否有最小的k使得k位置的前缀积和后缀积相等。

思路:计算2个数的前缀和即可,遍历判断。

AC Code:

#include <bits/stdc++.h>typedef long long ll;
const int N = 1e5 + 5;
int t, n;
int a[N], pre[N];int main() {std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);std::cin >> t;while(t --) {std::cin >> n;for(int i = 1; i <= n; i ++) {std::cin >> a[i];if(a[i] == 2)pre[i] = pre[i - 1] + 1;elsepre[i] = pre[i - 1];}int ans = -1;for(int i = 1; i <= n; i ++) {if(pre[i] == pre[n] - pre[i]) {ans = i;break;}}std::cout << ans << '\n';}return 0;
}

B. Sum of Two Numbers

给出一个数字n,求x和y,满足x+y=n,x和y的各位数之和相差不超过1。

思路:直接对于每一位均分即可。如果该位为奇数,1的个数交替给x和y。

AC Code:

#include <bits/stdc++.h>typedef long long ll;
const int N = 1e5 + 5;
int t, n;
bool vis[15];int main() {std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);std::cin >> t;while(t --) {std::cin >> n;char a[15] = {0}, b[15] = {0}, cnta = 0, cntb = 0;memset(vis, 0, sizeof(vis));std::string s = std::to_string(n);for(int i = 0; i < s.length(); i ++) {int num = s[i] - '0';if(!(num & 1))a[cnta ++] = num / 2 + '0', b[cntb ++] = num / 2 + '0';else {vis[cnta] = 1;a[cnta ++] = num / 2 + '0', b[cntb ++] = num / 2 + '0';}}int pos = 0;for(int i = 0; i <= 15; i ++) {if(vis[i]) {if(pos)a[i] = a[i] - '0' + 1 + '0';elseb[i] = b[i] - '0' + 1 + '0';pos ^= 1;}}int x = std::atoi(a), y = std::atoi(b);std::cout << x << ' ' << y << '\n';}return 0;
}

os:这个代码写的像shit一样。。。

C. Matching Numbers

给出1~2*n这些数,能否分成两两一组,使得每组的和是连续的数?

思路:很显然,n为偶数时,是不可以按要求分组的。n为奇数时,手摸几组样例可以知道,这个连续的数字是1+2*n-n/2 ~ 1+2*n+n/2,然后从大数开始,发现后n/2个数可以表示后n/2个和,下面n/2个数可以表示前n/2个和。

AC Code:

#include <bits/stdc++.h>typedef long long ll;
typedef std::pair<int, int> PII;
const int N = 2e5 + 5;
int t, n;
bool vis[N];int main() {std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);std::cin >> t;while(t --) {std::cin >> n;if(!(n & 1)) {std::cout << "NO" << '\n';continue;}std::vector<PII> vec;vec.push_back({n, n + 1});int num = 2 + 2 * n;for(int i = n * 2; i >= 2 * n - n / 2 + 1; i --) {vec.push_back({i, num - i});num ++;}num = 1 + 2 * n - n / 2;for(int i = 2 * n - n / 2; i >= n + 2; i --) {vec.push_back({i, num - i});num  ++;}std::cout << "YES" << '\n';for(auto [x, y] : vec)std::cout << x << ' ' << y << '\n';}return 0;
}

D. Moving Dots

在一个数轴上有n个数,每个点都以相同的速度移动,若是左右两点的距离不同,向距离较小的点移动;若是相同,则向左移动。两个点移动到一起时,他们会停下。对于每个子序列,问剩下的点的和是多少。

思路:每一对点,它会有贡献的时候是他们两个向中间相向而行,最后汇聚成一个点。那么我们可以计算每一对点的贡献,在一个字序列中,这对点有贡献的时候是他们两个两侧没有相距更小而使得这一对点向背而行,其他的点任选即可,即2^n中选择方法。

学习大佬的思路

AC Code:

#include <bits/stdc++.h>typedef long long ll;
const int N = 3e3 + 5;
const int mod = 1e9 + 7;
int n;
int a[N];template<const int T>
struct ModInt {const static int mod = T;int x;ModInt(int x = 0) : x(x % mod) {}ModInt(ll x) : x(int(x % mod)) {} int val() { return x; }ModInt operator + (const ModInt &a) const { int x0 = x + a.x; return ModInt(x0 < mod ? x0 : x0 - mod); }ModInt operator - (const ModInt &a) const { int x0 = x - a.x; return ModInt(x0 < 0 ? x0 + mod : x0); }ModInt operator * (const ModInt &a) const { return ModInt(1LL * x * a.x % mod); }ModInt operator / (const ModInt &a) const { return *this * a.inv(); }void operator += (const ModInt &a) { x += a.x; if (x >= mod) x -= mod; }void operator -= (const ModInt &a) { x -= a.x; if (x < 0) x += mod; }void operator *= (const ModInt &a) { x = 1LL * x * a.x % mod; }void operator /= (const ModInt &a) { *this = *this / a; }friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x;}ModInt pow(int64_t n) const {ModInt res(1), mul(x);while(n){if (n & 1) res *= mul;mul *= mul;n >>= 1;}return res;}ModInt inv() const {int a = x, b = mod, u = 1, v = 0;while (b) {int t = a / b;a -= t * b; std::swap(a, b);u -= t * v; std::swap(u, v);}if (u < 0) u += mod;return u;}};
typedef ModInt<1000000007> mint;mint pow2[N];int main() {std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);std::cin >> n;pow2[0] = 1;for(int i = 1; i <= n; i ++) {std::cin >> a[i];pow2[i] = pow2[i - 1] * 2;}mint ans = 0;for(int i = 1; i <= n; i ++) {for(int j = i + 1; j <= n; j ++) {int d = a[j] - a[i];int l = std::lower_bound(a + 1, a + 1 + n, a[i] - d) - a - 1;int r = std::lower_bound(a + 1, a + 1 + n, a[j] + d) - a;ans += pow2[l + n - r + 1];}}std::cout << ans << '\n';return 0;
}
http://www.yayakq.cn/news/568859/

相关文章:

  • 直播网站建设需要什么软件有哪些常德建设企业网站
  • vue.js合作做网站么html5浅蓝色网站设计公司dede模板
  • 做茶叶网站手机触屏网站开发教程
  • 中国空间站机械臂烟台做网站电话
  • 济南比较大的网站制作公司赚钱软件一天赚100元游戏无广告
  • 个人网站有哪些平台开发网站建设用什么框架
  • 做论坛app网站有哪些怎样提升网站关键词
  • 网站第三方登录怎么做深圳网址导航
  • 网站建设专业公司设计公司工作室创业规划
  • 免费广告设计制作网站大学网站建设目标
  • 网店推广有哪些方法无锡做网站seo的
  • 为某网站做网站推广策划方案环保工程网站建设价格
  • 企业网站的建立方法网页浏览器主要通过ftp协议同网页服务器
  • 创建公司网站用什么软件电子商务有限公司有哪些
  • 贵州省住房和城乡建设厅网站-首页金坛建设局招标网站
  • 烟台专业网站建设公司哪家好辽宁建设工程信息网上传标书时显示初始化签名证书选择模式失败
  • 江西做网站多少钱oppo开放平台
  • 查网站是否正规app制作定制外包22
  • 专业网站设计建设外链论坛
  • 绥中做网站公司网站pv uv 多少算好站
  • 太仓企业网站建设公司dw安装免费下载
  • 企业网站建设销售前景单位建立一个官网多少钱
  • 亳州网站建设费用廊坊网站推广外包
  • 宜兴做网站哪家好北京企业模板建站
  • 做专利费减是哪个网站上海风险地区划分最新查询
  • xyz域名注册局官方网站网页设计制作教程:一个页面的完全制作
  • 专业购物网站定制品牌网站开发动态模块
  • 广州专业网站建设报价制作设计图的网页
  • 上海 网站制作空间网站打不开
  • 搭建网站是什么专业dede做的网站怎样去换模版