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

6.18总结

省赛排位赛2:

省赛排名赛2 - Virtual Judge

思路:

设两个方程直接解出来就行

代码:

#include<bits/stdc++.h>
using namespace std;
int n, m; 
int main()
{int n, m;int ans1, ans2;cin >> n >> m;ans1 = n - (-3 + sqrt(3 * 3 + 4 * 2 * (n + m))) / 2;ans2 = n - (-3 - sqrt(3 * 3 + 4 * 2 * (n + m))) / 2;if (ans1 <= n && ans2 >= 0) cout << ans1;else cout << ans2;
}

省赛排名赛2 - Virtual Judge
代码:

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n;
int main()
{int t;cin >> t;while (t--){cin >> n;ll ans = 0;ll nn = n;ll i = 1;while (nn){ans += n / i;i <<= 1ll;nn >>= 1ll;}cout << ans << endl;}return 0;
}

省赛排名赛2 - Virtual Judge

代码:

#include<bits/stdc++.h>
using namespace std;
int a[10000005];
int main()
{int n, p;cin >> n >> p;for (int i = 1; i <= n; i++){cin >> a[i];a[i] += a[i - 1];}int ans = 0;for (int i = 1; i < n; i++){ans = max(ans, (a[i] % p + (a[n] - a[i]) % p));}cout << ans << endl;return 0;
}

省赛排名赛2 - Virtual Judge

思路:

需要得到每个(x,y)下的最大公约数,再找出一定的规律

代码:

#include<bits/stdc++.h>
using namespace std;
long long t, a, b, c, n, ca, cb, cc;
int gcd(int x, int y)
{if (x < y)swap(x, y);if (x % y)return gcd(y, x % y);return y;
}
int main()
{cin >> t;while (t--){cin >> n >> a >> b;c = a * b / gcd(a, b);ca = n / a, cb = n / b, cc = n / c;ca -= cc, cb -= cc;cout << (n + n - ca + 1) * ca / 2 - (1 + cb) * cb / 2 << endl;}return 0;
}

省赛排名赛2 - Virtual Judge

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[1000010], n;
int main() {cin >> n;for (int i = 1; i <= n; i++)cin>>a[i], a[i] ^= a[i - 1];ll ans = 0;for (int i = 0, x = (1 << i); i < 32; i++, x <<= 1){int cnt = 0;for (int j = 1; j <= n; j++)if ((a[j] >> i) & 1) cnt++;ans += 1LL * cnt * (n + 1 - cnt) * x;}cout << ans << endl;return 0;
}

省赛排名赛2 - Virtual Judge

思路:

给定一个能达到数据范围的斐波拉契数组,包含所有数据范围内的斐波拉契数,再进行几个特判

代码:


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll f[100];
string check(ll n, ll x, ll y)
{if (x == 1 && y == 1){return "YES";}if (y <= f[n] && y > f[n - 1]){return "NO";}if (y > f[n]){y = y - f[n];}return check(n - 1, y, x);
}
int main()
{ll t, n, x, y;f[0] = 1;f[1] = 1;for (int i = 2; i <= 45; i++)f[i] = f[i - 1] + f[i - 2];cin >> t;while (t--){cin >> n >> x >> y;cout << check(n, x, y) << endl;;}return 0;
}

省赛排名赛2 - Virtual Judge

思路:

01背包问题,就题目改了一下,直接用模板就行

代码:

#include<bits/stdc++.h>
using namespace std;
int h, t, n, a[401], z[401], l[501], dp[401][401];
int main() {cin >> h >> t >> n;for (int i = 1; i <= n; i++){cin >> a[i] >> z[i] >> l[i];}for (int i = 1; i <= n; i++){for (int j = h; j >= a[i]; j--){for (int k = t; k >= z[i]; k--){dp[j][k] = max(dp[j][k], dp[j - a[i]][k - z[i]] + l[i]);}}}cout << dp[h][t];return 0;
}

http://www.lryc.cn/news/375974.html

相关文章:

  • 【ARM Cache 及 MMU 系列文章 1.4 -- 如何判断 L3 Cache 是否实现?】
  • 打印mybatis的sql日志
  • QT day4(对话框 事件机制)
  • 序列化与反序列化漏洞实例
  • 6、while循环 - 习题解析
  • ReentrantLock可重入锁
  • 如何秒杀系统架构设计
  • 深度神经网络——什么是降维?
  • SpringMVC—RequestMapping注解
  • Java线程池基本概念
  • 智能车联网安全发展形势、挑战
  • AWS概述
  • MySQL常见面试题自测
  • c语言回顾-函数递归
  • 消息队列-RabbitMQ-延时队列实现
  • 【热门开源项目推荐】满足不同程序员的需求与关注点
  • 一文理清GO语言日志库实现开发项目中的日志功能(rotatelogs/zap分析)
  • 【Go语言精进之路】构建高效Go程序:了解string实现原理并高效使用
  • HDFS 常见命令
  • 示例:WPF中应用Grid的SharedSizeGroup设置整齐的布局
  • React的form表单自定义校验规则
  • 一种新的一维时间序列信号盲解卷积算法(以旋转机械故障诊断为例,MATLAB环境)
  • 618电商是社区网站入局的好时机吗?
  • 不知道密码,一样能卸载瑞星esm防病毒终端安全防护系统
  • Chromium 开发指南2024 Mac篇-安装和配置depot_tools工具(三)
  • 微信小程序-路由和页面跳转API
  • PWR电源控制
  • 【记录46】【案例】echarts 柱状图
  • Github2024-06-12 开源项目日报 Top10
  • 茶艺师服务师傅小程序APP源码(APP+小程序+公众号+H5)