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

牛客周赛 Round 110 E,F题解

E、小苯的数字变换

题意:

小苯在研究一种特殊的数字变换。对于一个正整数 \(x\),定义一个数字的“根”为不断将其各位数字相加直到得到个位数。例如:

\[\text{根}(38) = 3 + 8 = 11 \rightarrow 1 + 1 = 2 \]

\[\text{根}(999) = 9 + 9 + 9 = 27 \rightarrow 2 + 7 = 9 \]

现在给定一个数字串 \(x\),请你求出:所有 \(x\) 的连续子区间代表的十进制数字(去掉前导 0 后)的 “根” 之和。

思路:

考虑\(dp\)
\(dp[i][j]\)表示以第\(i\)个数字结尾,“根”的和为\(j\)的子序列个数
具体细节见代码

代码

#include<bits/stdc++.h>
#define ll long long
#define ce cerr
#define ull unsigned long long
#define lll __int128
#define PII pair<int, int>
#define PLL pair<long ,long>using namespace std;const int inf = 0x3f3f3f3f;
const ll iinf = 1e18;//cin.ignore(std::numeric_limits< streamsize >::max(), '\n');
int t;void solve() {string s;cin >> s;int n = s.size ();s=  ' ' + s;vector<ll> a (n + 1);vector<vector<ll> > dp (n + 1, vector<ll> (10, 0));for (int i = 1; i <= n; ++i) {a[i] = (int) s[i] - '0';}// dp[i][j] : 第i个数字结尾,“根”之和为j的连续子区间的个数for (int i = 1; i <= n; ++i) {for (int j = 0; j <= 9; ++j) {int num = s[i] - '0';int temp = num + j;if (temp >= 10) temp -= 9;dp[i][temp] += dp[i - 1][j];}dp[i][a[i]] ++;}ll res = 0;for (int i = 1; i <= n; ++i) {for (int j = 0; j <= 9; ++j) {res += dp[i][j] * j;}}cout << res << "\n";
}
int main() {ios::sync_with_stdio (false);cin.tie(NULL);cout.tie(NULL);t = 1;cin >> t;while (t --) {solve();}return 0;
}

F、小苯的序列合并

题意:

给定长度为 \(n\) 的序列 \(a\),你可以对 \(a\) 做如下操作任意次:

  • 选择一个下标 \(i \ (1 \leq i < |a|)\),将 \(a_i\)\(a_{i+1}\) 合并起来,结果为 \(a_i \oplus a_{i+1}\)。(其中 \(\oplus\) 表示按位异或运算符,\(|a|\) 表示 \(a\) 当前的长度。)

所有操作结束后,小苯希望你最大化最终 \(a\) 中所有数字的按位与,即 AND(&)值,请你算一下这个最大值是多少吧。

思路:

关键点:最优解最多只会划分成两段(进行&的段数\(\leq 2\)
对于三个数字一定有:\(x_1 \oplus x_2 \oplus x_3 >= x_1 \& x_2 \& x_3\)(这里异或顺序不定)
所以,对于大于等于三段的分段方法,一定能够通过相邻三个数字之间不断异或,得到最终一个或者两个数字进行与运算

代码

#include<bits/stdc++.h>
#define ll long long
#define ce cerr
#define ull unsigned long long
#define lll __int128
#define PII pair<int, int>
#define PLL pair<long ,long>using namespace std;const int inf = 0x3f3f3f3f;
const ll iinf = 1e18;//cin.ignore(std::numeric_limits< streamsize >::max(), '\n');
int t;void solve() {int n;cin >> n;vector<ll> a (n + 1);vector<ll> b (n + 1);for (int i = 1; i <= n; ++i) {cin >> a[i];b[i] = b[i - 1] ^ a[i];}ll res = b[n];for (int i = 0; i <= n; ++i) {//ce << b[i] <<" " << (b[n] ^ b[i]) << "\n";res = max (res, b[i] & (b[n] ^ b[i]));}cout << res << "\n";
}
int main() {ios::sync_with_stdio (false);cin.tie(NULL);cout.tie(NULL);t = 1;cin >> t;while (t --) {solve();}return 0;
}
http://www.sczhlp.com/news/130227/

相关文章:

  • 第5章:路由(Routing)与直连交换机(Direct Exchange)
  • 做网站 域名是怎么回事建设简单网站的图纸
  • 无锡网站排名推广潍坊网页设计公司
  • 淄博网站建设兼职基本网页设计
  • 上海专业做网站服务商营销策略是什么意思
  • 网站如何诊断网络推广公司 深圳
  • 做网站抽奖系统网站没有关键词的弊端
  • 建设部网站 干部学院 一级注册建筑师培训 2014年那个网站做图片
  • 邢台建设局网站上中标公示查询研究院网站建设
  • 校园网站怎么建设公司logo设计注意事项
  • 成都网站建设设计营销型网站建设风格设定
  • 搜索百科(4):OpenSearch — 开源搜索的新选择
  • 网站建设行业话术vm虚拟化建设网站
  • 兰州网站建设兰州wordpress防止镜像
  • 专业手机网站建设公司邵阳网站建设公司
  • 企业网站管理系统最新4湖南岚鸿牛x1 0app开发制作定制外包26
  • 网站如何建立品牌形象响应式网站做法
  • 如何给网站2做推广接做网站私活
  • 手机版网站开发框架网站建设灬金手指下拉十五
  • 重庆网站建设letide音乐网站建设成本
  • 站长素材网如何制作个人作品网站
  • 搭建个人网站的步骤行业门户网站模板下载
  • 万网站建设vs2015做网站如何添加控件
  • 虚拟服务器和如何创建网站福州专业建站
  • 做品牌网站哪个好用湖北网站
  • 网上做调查问卷赚钱的网站网站建设公司推广
  • 哪些公司做网站好wordpress怎么进
  • ppt免费下载的网站专做蓝领的网站
  • 个人可以建网站卖东西吗长春网长春关键词排名站设计
  • 品牌网站建设 t磐石网络wordpress如何添加目录菜单