1. f1 score

首先了解f1 score的计算方法, 我记得是学信息检索知道的, 然后简单处理就行。 由于我写的比较麻烦, 中间处理过程引入了一些除数为0的情况,导致错了很多次。其实是很简单的。

 #include<bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e3 + ; char c1x[], c2x[];
void solve() {
int n;
int a, b, c, d;
a = b = c = d = ;
scanf("%d", &n);
char c1, c2;
for (int i = ; i < n; i++) {
scanf("%s%s", c1x, c2x);
c1 = c1x[];c2 = c2x[];
//cout << c1 << " " << c2 << endl;
if(c1 == '+') {
if(c2 == '+') a++;
else b++;
} else {
if(c2 == '+') c++;
else d++;
}
}
//if(a + b == 0 || a + c == 0) {
// printf("0.00%%\n");
// return;
//}
//double x1 = a + b == 0 ? 0 : 1.0 * a / (a + b);
//double x2 = a + c == 0 ? 0 : 1.0 * a / (a + c);
//double res = (x1 + x2 == 0) ? 0 : 100.0 * 2 * (x1 * x2) / ((x1 + x2));
double res = 100.0 * * a / (2.0 * a + b + c);
printf("%.2f%%\n", res);
} int main() {
//freopen("test.in", "r", stdin); solve();
return ;
}

2. 数组重排2

没有做出来。当时的考虑是:最差情况下需要移动 n-1次,而不是n次。每次移动之后不知道怎么考虑。想了好久没有想出来。

后来看答案,就是从末尾向前找,从n开始,连续的能得到几个,剩下的都是需要移动的。感觉很巧妙。关键在于理解不需要移动的,最多有多少个。

 #include<bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e5 + ; int n;
int a[maxn];
void solve() {
cin >> n;
for (int i = ; i < n; i++)
cin >> a[i];
int t = n;
for (int i = n - ; i >= ; i--) {
if(a[i] == t) {
t--;
}
}
cout << t << endl;
} int main() {
freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
ios::sync_with_stdio();
cin.tie(); cout.tie();
solve();
return ;
}

3. 逆序对

很经典的问题, mergesort或者树状数组。我写的不熟练,花费了一些时间。

 #include<bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e5 + ;
int f[maxn];
int n;
int lb(int x) {
return x & -x;
}
void update(int x) {
while(x <= n) {
f[x]++;
x += lb(x);
}
}
int ask(int x) {
int r = ;
while(x > ) {
r += f[x];
x -= lb(x);
}
return r;
}
int a[maxn];
void solve() {
cin >> n;
for (int i = ; i < n; i++) cin >> a[i];
ll res = ;
for (int i = n - ; i >= ; i--) {
res += ask(a[i]);
update(a[i]);
}
cout << res << endl;
} int main() {
freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
ios::sync_with_stdio();
cin.tie(); cout.tie();
solve();
return ;
}
 #include<bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e5 + ;
int a[maxn], b[maxn];
int n;
ll res;
void mg(int left, int mid, int right) {
int x = left, y = mid;
for (int i = left; i <= right; i++) {
if(y > right || ( x < mid && a[x] <= a[y])) {
b[i] = a[x];
x++;
} else {
res += (mid - x);
//cout << x << " " << y <<endl;
// cout << left << " " << mid << " " << right <<endl;
//cout << res << endl;
b[i] = a[y]; y++;
}
}
memcpy(a + left, b + left, sizeof(int) * (right - left + ));
}
void mgsort(int left, int right) {
if(left >= right) return;
int mid = (left + right) / ;
mgsort(left, mid);
mgsort(mid + , right);
mg(left, mid + , right);
}
void solve() {
cin >> n;
for (int i = ; i < n; i++) cin >> a[i];
mgsort(, n - );
cout << res << endl;
} int main() {
freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
ios::sync_with_stdio();
cin.tie(); cout.tie();
solve();
return ;
}

4. 逃离迷宫3

不知道怎么怎么做,感觉很麻烦。

分析起来比较复杂,暂时先放弃了。

hihocode 编程练习赛17的更多相关文章

  1. [.net 面向对象编程基础] (17) 数组与集合

    [.net 面向对象编程基础] (17) 数组与集合 学习了前面的C#三大特性,及接口,抽象类这些相对抽象的东西以后,是不是有点很累的感觉.具体的东西总是容易理解,因此我们在介绍前面抽象概念的时候,总 ...

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

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

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

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

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

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

  5. 泛函编程(17)-泛函状态-State In Action

    对OOP编程人员来说,泛函状态State是一种全新的数据类型.我们在上节做了些介绍,在这节我们讨论一下State类型的应用:用一个具体的例子来示范如何使用State类型.以下是这个例子的具体描述: 模 ...

  6. hiho #1272 买零食 [Offer收割]编程练习赛2

    #1272 : 买零食 时间限制:5000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho很喜欢在课间去小卖部买零食.然而不幸的是,这个学期他又有在一教的课,而一教的小卖部姐姐以冷若冰 ...

  7. Linux系统编程(17)——正则表达式进阶

    C的变量和Shell脚本变量的定义和使用方法很不相同,表达能力也不相同,C的变量有各种类型,而Shell脚本变量都是字符串.同样道理,各种工具和编程语言所使用的正则表达式规范的语法并不相同,表达能力也 ...

  8. C++编程练习(17)----“二叉树非递归遍历的实现“

    二叉树的非递归遍历 最近看书上说道要掌握二叉树遍历的6种编写方式,之前只用递归方式编写过,这次就用非递归方式编写试一试. C++编程练习(8)----“二叉树的建立以及二叉树的三种遍历方式“(前序遍历 ...

  9. hihoCoder编程练习赛49

    题目1 : 相似颜色 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 在CSS中我们可以用井号(#)加6位十六进制数表示一种颜色,例如#000000是黑色,#ff0000 ...

随机推荐

  1. kata练习题

    This time no story, no theory. The examples below show you how to write function accum: Examples: ac ...

  2. Spring MVC 概述

    [简介] Spring MVC也叫Spring web mvc,属于表现层的框架.SpringMVC是Spring框架的一部分,是在Spring 3.0后发布的. 由以上Spring的结构图可以看出, ...

  3. 九度oj 题目1066:字符串排序

    题目1066:字符串排序 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6487 解决:2670 题目描述: 输入一个长度不超过20的字符串,对所输入的字符串,按照ASCII码的大小从小到 ...

  4. vim高亮显示当前行列

    vim高亮显示当前行: set cursorline vim高亮显示当前列: set cursorcolumn

  5. jquery动态为个span,input,div,等标签赋值的方法总结,js动态隐藏div

    1.jquery为span和div标签赋值. <span id="span1"></span> <div id="div1"> ...

  6. 洛谷—— P1339 [USACO09OCT]热浪Heat Wave

    P1339 [USACO09OCT]热浪Heat Wave 题目描述 The good folks in Texas are having a heatwave this summer. Their ...

  7. 4560 NOIP2015 D2T2 子串 code vs

    4560 NOIP2015 D2T2 子串  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 有两个仅包含小写 ...

  8. Swift: 转换NSString to String

    如下代码获取一个String?的结果 let s = NSString(data: data, encoding: encoding) return s as? String

  9. Nexus设备升级5.0方法

    1. 从该页面为您的设备下载适当的系统映像.然后将它解压缩到一个安全的文件夹. 2. 通过 USB 连接到您的计算机. 3. 使用下列的方法,在fastboot mode下启动设备: 使用 adb   ...

  10. Object-C---&gt;Swift之(十一)属性观察者

    属性观察者机制能让程序在属性被赋值时获得运行代码的机会,用来监视属性的除初始化之外的属性值变化,当属性值发生改变时能够对此作出响应 详细包含两个特殊的回调方法: willSet(newValue):被 ...