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. (转)基于MVC4+EasyUI的Web开发框架经验总结(10)--在Web界面上实现数据的导入和导出

    http://www.cnblogs.com/wuhuacong/p/3873498.html 数据的导入导出,在很多系统里面都比较常见,这个导入导出的操作,在Winform里面比较容易实现,我曾经在 ...

  2. 查看占用某端口的进程——netstat、findstr 的使用

    netstat   检验本机各端口的网络连接情况 -a 显示所有连接和侦听端口(如Windows共享服务 的135,445端口) -n 不进行IP地址到主机名的解析 -o 显示拥有的与每个连接关联的进 ...

  3. python 直接存入Excel表格

    def write_excels(self, document): outwb = openpyxl.Workbook() outws = outwb.create_sheet(index=0) fo ...

  4. BOS工具之BOS应用框架

    大纲:    应用框架概述,bos应用框架总体,bos应用框架详细设计,代码结构以及常用应用,开发常用接口 框架(Framework)是整个或部分系统的可重用设计,表现为一组抽象组件及组件实例间交互的 ...

  5. [luogu2624 HNOI2008]明明的烦恼 (prufer+高精)

    传送门 Solution 根据prufer序列做的题,具体可以看这里 还知道了一种避免高精除的方法quq Code #include <cmath> #include <cstdio ...

  6. Python中的特殊方法:__call__

    本文结构: 1.__call__方法 2.callable():判断对象/函数能否被调用 3.举例:斐波那契数列类 1.__call__方法 一个对象实例可以有自己的属性和方法,当我们调用实例方法时, ...

  7. hdu 4858 容器的简单模拟

    我用临接表模拟容器超时 #include<stdio.h> #include<string.h> #include<vector> using namespace ...

  8. 0316 【案例】MySQL count操作优化案例一则

      转自http://blog.itpub.net/22664653/viewspace-1791124/ 一 背景 某业务的数据库定期报 thread_runing 飙高,通定位发现一个慢查询sql ...

  9. [bzoj2259][Oibh]新型计算机_Dijkstra

    新型计算机 bzoj-2259 Oibh 题目大意:给定一个n个数的数列,第i个数为a[i],更改第i个数至x的代价为|x-a[i]|.求最小代价,使得:读入一个数s1后,向后连着读s1个数,然后如s ...

  10. Spring Boot 配置Oracle数据库

    1.添加oralce 依赖包,仓库没有则通过maven装载到本地仓库: 2.application.properties 中添加配置,特别是第一个配置项要严重注意! spring.jpa.databa ...