AEIOU

选出的子串中由AEI构成的子串和由OU构成的子串之间并没有什么关系,分别算出最长的加起来。

#pragma comment(linker, "/STACK:102400000,102400000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<functional>
#include<math.h>
//#include<bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} string s;
int dp[];
int p[]; int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
cin >> s;
int n = s.size();
int max1 = , max2 = ;
memset(dp, , sizeof(dp));
for (int i = ; i < ; i++) p[i] = -;
for (int i = ; i < n; i++) {
if (s[i] == 'a') {
dp[i] = ;
if (p['a'] != -) dp[i] = max(dp[i], dp[p['a']] + );
if (dp[i] > dp[p['a']]) p['a'] = i;
}
if (s[i] == 'e') {
dp[i] = ;
if (p['a'] != -) dp[i] = max(dp[i], dp[p['a']] + );
if (p['e'] != -) dp[i] = max(dp[i], dp[p['e']] + );
if (dp[i] > dp[p['e']]) p['e'] = i;
}
if (s[i] == 'i') {
dp[i] = ;
if (p['a'] != -) dp[i] = max(dp[i], dp[p['a']] + );
if (p['e'] != -) dp[i] = max(dp[i], dp[p['e']] + );
if (p['i'] != -) dp[i] = max(dp[i], dp[p['i']] + );
if (dp[i] > dp[p['i']]) p['i'] = i;
}
max1 = max(max1, dp[i]);
}
memset(dp, , sizeof(dp));
for (int i = ; i < ; i++) p[i] = -;
for (int i = ; i < n; i++) {
if (s[i] == 'o') {
dp[i] = ;
if (p['o'] != -) dp[i] = max(dp[i], dp[p['o']] + );
if (dp[i] > dp[p['o']]) p['o'] = i;
}
if (s[i] == 'u') {
dp[i] = ;
if (p['o'] != -) dp[i] = max(dp[i], dp[p['o']] + );
if (p['u'] != -) dp[i] = max(dp[i], dp[p['u']] + );
if (dp[i] > dp[p['u']]) p['u'] = i;
}
max2 = max(max2, dp[i]);
}
cout << max1 + max2 << endl;
return ;
}

数字游戏

这题看别人的代码貌似跟全排列有关,但是没想通关系在哪。

我的解法是这样的:首先加减和交换的顺序并不会影响操作的步数,所以可以看做是先进行若干步交换,然后依次把每一位加减为B的对应位数字。以A为初始状态进行bfs,然后卡时,就过了、

#pragma comment(linker, "/STACK:102400000,102400000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<functional>
#include<math.h>
//#include<bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} char A[], B[];
int cost[][];
lint p[];
int n;
struct state {
int step;
char num[];
bool operator < (state s) const {
if (step == s.step) return false;
else return step > s.step;
}
};
lint calc(state s) {
lint rtn = ;
for (int i = ; i < n; i++) rtn += s.num[i] * p[n - i - ];
return rtn;
}
map<lint, int> mp;
priority_queue<state> q; int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
scanf("%d%s%s", &n, A, B);
for (int i = ; i < n; i++) {
A[i] -= '';
B[i] -= '';
}
p[] = ;
for (int i = ; i < ; i++) p[i] = p[i - ] * ;
for (int i = ; i < ; i++) {
for (int j = ; j < ; j++) {
if (i == j) cost[i][j] = ;
if (i > j) cost[i][j] = cost[j][i];
if (i < j) cost[i][j] = min(j - i, i + - j);
}
}
lint b = ;
for (int i = ; i < n; i++) b += B[i] * p[n - i - ];
state s, u;
s.step = ;
memcpy(s.num, A, sizeof(A));
q.push(s);
mp[calc(s)] = ;
int ans = , iter = ;
while (!q.empty()) {
s = q.top();
q.pop();
int step = s.step;
for (int i = ; i < n; i++) step += cost[s.num[i]][B[i]];
ans = min(ans, step);
iter++;
if (iter > ) break;
for (int i = ; i < n; i++) {
for (int j = i + ; j < n; j++) {
u = s;
char t = u.num[i];
u.num[i] = u.num[j];
u.num[j] = t;
u.step++;
lint c = calc(u);
if (mp.find(c) != mp.end()) continue;
else {
mp[c] = ;
q.push(u);
}
}
}
}
cout << ans << endl;
return ;
}

第K小分数

前K个分数显然由每个质数构成的分数的前连续若干项构成,由于最多有1000个质数,所以最多有1000个最后一项,所以第K个分数一定是这最多1000个最后一项中的一个。可以用二分法来确定每种分母的最后一项并计算其排名,若其排名为K,则找到了题目要求的分数。

#pragma comment(linker, "/STACK:102400000,102400000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<functional>
#include<math.h>
//#include<bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} lint p[]; int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
int n;
lint k;
cin >> n >> k;
for (int i = ; i < n; i++) cin >> p[i];
for (int i = ; i < n; i++) {
lint l = , r = p[i], mid;
while (l + < r) {
mid = (l + r) >> ;
lint tmp = ;
for (int j = ; j < n; j++) tmp += mid * p[j] / p[i];
if (tmp == k) cout << mid << '/' << p[i] << endl;
if (tmp <= k) l = mid;
else r = mid;
}
}
return ;
}

逆序异或和

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = ;

int n, a[N];

struct BIT {
int c[N];
void init() {
memset(c, , sizeof(c));
}
void insert(int x) {
for (; x < N; x += x & -x) c[x] ++;
}
int count(int x, int res=) {
for (; x; x ^= x & -x) res += c[x];
return res;
}
}bit[], num; int main() {
scanf("%d", &n);
for (int i = ; i <= n; ++i) scanf("%d", a + i);
num.init();
for (int i = ; i < ; ++i) bit[i].init();
ll ans = ;
for (int i = n; i >= ; --i) {
int tar = num.count(a[i] - );
num.insert(a[i]); for (int j = ; j < ; ++j) {
int _num = << j;
int _bit = a[i] & _num;
int _bit_tar = bit[j].count(a[i] - );
if (_bit) {
ans += 1LL * _num * (tar - _bit_tar);
bit[j].insert(a[i]);
}
else {
ans += 1LL * _num * _bit_tar;
}
}
}
cout << ans << endl;
return ;
}

[hihocoder][Offer收割]编程练习赛46的更多相关文章

  1. hihocoder [Offer收割]编程练习赛4

    描述 最近天气炎热,小Ho天天宅在家里叫外卖.他常吃的一家餐馆一共有N道菜品,价格分别是A1, A2, ... AN元.并且如果消费总计满X元,还能享受优惠.小Ho是一个不薅羊毛不舒服斯基的人,他希望 ...

  2. [Offer收割]编程练习赛46

    [Offer收割]编程练习赛46赛后题解 A.AEIOU 分析

  3. hihocoder [Offer收割]编程练习赛61

    [Offer收割]编程练习赛61 A:最小排列 给定一个长度为m的序列b[1..m],再给定一个n,求一个字典序最小的1~n的排列A,使得b是A的子序列. 贪心即可,b是A的子序列,把不在b中的元素, ...

  4. ACM学习历程—Hihocoder [Offer收割]编程练习赛1

    比赛链接:http://hihocoder.com/contest/hihointerview3/problem/1 大概有一个月没怎么打算法了.这一场的前一场BC,也打的不是很好.本来Div1的A和 ...

  5. hihocoder offer收割编程练习赛8 C 数组分拆

    思路:(引自bfsoyc的回答:http://hihocoder.com/discuss/question/4160) 动态规划.状态dp[i]表示 前i个数的合法的方案数,转移是 dp[i] = s ...

  6. hihocoder [Offer收割]编程练习赛18 C 最美和弦(dp)

    题目链接:http://hihocoder.com/problemset/problem/1532 题解:一道基础的dp,设dp[i][j][k][l]表示处理到第几个数,当前是哪个和弦错了几次初始x ...

  7. hihoCoder [Offer收割]编程练习赛3 D子矩阵求和

    子矩阵求和 http://hihocoder.com/discuss/question/3005 声明一下: n是和x一起的,m是和y一起的 x是横着的,y是纵着的,x往右为正,y往下为正 (非常反常 ...

  8. hihocoder [Offer收割]编程练习赛52 D 部门聚会

    看了题目的讨论才会做的 首先一点,算每条边(u, v)对于n*(n+1)/2种[l, r]组合的贡献 正着算不如反着算 哪些[l, r]的组合没有包含这条边(u, v)呢 这个很好算 只需要统计u这半 ...

  9. hihocoder [Offer收割]编程练习赛14

    A.小Hi和小Ho的礼物 谜之第1题,明明是第1题AC率比C还要低.题目是求在n个不同重量袋子选4袋,2袋给A,2袋给B,使2人获得重量相同,求问方案数. 我也是一脸懵b...o(n2)暴力枚举发现把 ...

随机推荐

  1. webSphere

    WebSphere 是 IBM 的软件平台.它包含了编写.运行和监视全天候的工业强度的随需应变 Web 应用程序和跨平台.跨产品解决方案所需要的整个中间件基础设施,如服务器.服务和工具.WebSphe ...

  2. 分布式锁获取token

    package com.sankuai.qcs.regulation.nanjing.util; import com.dianping.squirrel.client.StoreKey; impor ...

  3. xpath 获取深圳房源信息并导出csv

    # -*- coding: utf-8 -*- # @Time : 2019/4/28 10:44 # @Author : wujf # @Email : 1028540310@qq.com # @F ...

  4. eas之编码规则&单据转换规则

    *当在企业建模中没有要显示的项目的话,则从包更新到系统树然后选择到规则定义,对申请单新增规则. 企业建模--业务规则-规则定义组织优先  多组织有先  集团优先固定值 显示格式PUR ..系统日期 2 ...

  5. eas之新建窗口

    public void actionObjectProp_actionPerformed(ActionEvent e)          throws Exception {     UIContex ...

  6. 【剑指Offer】54、字符流中第一个不重复的字符

      题目描述:   请实现一个函数用来找出字符流中第一个只出现一次的字符.例如,当从字符流中只读出前两个字符"go"时,第一个只出现一次的字符是"g".当从该字 ...

  7. [jzoj 5782]【NOIP提高A组模拟2018.8.8】 城市猎人 (并查集按秩合并+复杂度分析)

    传送门 Description 有n个城市,标号为1到n,修建道路花费m天,第i天时,若gcd(a,b)=m-i+1,则标号为a的城市和标号为b的城市会建好一条直接相连的道路,有多次询问,每次询问某两 ...

  8. 9day条件语句和基本数据类型

    1基本数据类型: 字符串‘’," ",''' ''' 单引号,双引号,三引号 加法: n1='ruser' n2='sb' n3=n1+n2 print(n3) 乘法: n1='r ...

  9. 常用rides命令

    rides使用步骤 1.源代码构建安装 1.下载,Linux下命令wget http://redis.io/download下载redis的包 2.解归档Linux下命令tar -xvf redis- ...

  10. Spring Cloud系列(二) 介绍

    Spring Cloud系列(一) 介绍 Spring Cloud是基于Spring Boot实现的微服务架构开发工具.它为微服务架构中涉及的配置管理.服务治理.断路器.智能路由.微代理.控制总线.全 ...