hihocode 编程练习赛17
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的更多相关文章
- [.net 面向对象编程基础] (17) 数组与集合
[.net 面向对象编程基础] (17) 数组与集合 学习了前面的C#三大特性,及接口,抽象类这些相对抽象的东西以后,是不是有点很累的感觉.具体的东西总是容易理解,因此我们在介绍前面抽象概念的时候,总 ...
- hihocoder [Offer收割]编程练习赛4
描述 最近天气炎热,小Ho天天宅在家里叫外卖.他常吃的一家餐馆一共有N道菜品,价格分别是A1, A2, ... AN元.并且如果消费总计满X元,还能享受优惠.小Ho是一个不薅羊毛不舒服斯基的人,他希望 ...
- hihocoder [Offer收割]编程练习赛61
[Offer收割]编程练习赛61 A:最小排列 给定一个长度为m的序列b[1..m],再给定一个n,求一个字典序最小的1~n的排列A,使得b是A的子序列. 贪心即可,b是A的子序列,把不在b中的元素, ...
- [Offer收割]编程练习赛46
[Offer收割]编程练习赛46赛后题解 A.AEIOU 分析
- 泛函编程(17)-泛函状态-State In Action
对OOP编程人员来说,泛函状态State是一种全新的数据类型.我们在上节做了些介绍,在这节我们讨论一下State类型的应用:用一个具体的例子来示范如何使用State类型.以下是这个例子的具体描述: 模 ...
- hiho #1272 买零食 [Offer收割]编程练习赛2
#1272 : 买零食 时间限制:5000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho很喜欢在课间去小卖部买零食.然而不幸的是,这个学期他又有在一教的课,而一教的小卖部姐姐以冷若冰 ...
- Linux系统编程(17)——正则表达式进阶
C的变量和Shell脚本变量的定义和使用方法很不相同,表达能力也不相同,C的变量有各种类型,而Shell脚本变量都是字符串.同样道理,各种工具和编程语言所使用的正则表达式规范的语法并不相同,表达能力也 ...
- C++编程练习(17)----“二叉树非递归遍历的实现“
二叉树的非递归遍历 最近看书上说道要掌握二叉树遍历的6种编写方式,之前只用递归方式编写过,这次就用非递归方式编写试一试. C++编程练习(8)----“二叉树的建立以及二叉树的三种遍历方式“(前序遍历 ...
- hihoCoder编程练习赛49
题目1 : 相似颜色 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 在CSS中我们可以用井号(#)加6位十六进制数表示一种颜色,例如#000000是黑色,#ff0000 ...
随机推荐
- 第十五节:Web爬虫之selenium动态渲染爬取
selenium是一个用于Web应用程序测试的工具.Selenium测试直接运行在浏览器中,就像真正的用户在操作一样.支持的浏览器包括IE(7, 8, 9, 10, 11),Mozilla Firef ...
- 移动端禁止滑动的js处理方式
下面是禁止移动端滑动事件的方式,慎用 document.querySelector('body').addEventListener('touchmove', function (ev) { ...
- 洛谷 3178 [HAOI2015]树上操作
[题解] 就是个树链剖分的模板题. #include<cstdio> #include<algorithm> #include<cstring> #define L ...
- 【Codeforces 992B】Nastya Studies Informatics
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 因为gcd(a,b)=x 所以设a = nx b = mx 又有ab/gcd(a,b)=lcm(a,b)=y 则nmx = y 即n(m*x) ...
- 虚拟机中的CentOS7如何上网?---https://blog.csdn.net/nothing2017/article/details/61420767
虚拟机中的CentOS7如何上网?https://blog.csdn.net/nothing2017/article/details/61420767
- 解决使用myeclipse电脑卡的问题
1. 原因:myeclipse会自动更新,因此会占用大量内存 2. 解决方法: (1)window->Perferences->General->Startup and Shutdo ...
- 为 Windows Phone 8.1 app 解决“The type does not support direct content.”的问题
我在 VS 14 CTP 中新建了一个空的 app store 项目名叫 PlayWithXaml ,项目的 MainPage.xaml 文件改为了以下内容: <Page x:Class=&qu ...
- [bzoj 1042][HAOI2008]硬币购物(用容斥原理弄背包)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1042 分析: 解法很巧妙,用f[i]表示四种硬币A.B.C.D的数量不考虑的情况下弄成 ...
- NIO基础学习——缓冲区
NIO是对I/O处理的进一步抽象,包含了I/O的基础概念.我是基于网上博友的博客和Ron Hitchens写的<JAVA NIO>来学习的. NIO的三大核心内容:缓冲区,通道,选择器. ...
- Eclipse查看方法/类调用的方法
1.(首推)双击选中该方法/类,[Ctrl]+[Alt]+[H](Open Call Hierarchy) 2.(次推)选中该方法/类,[Ctrl]+[Shift]+[G](References) 3 ...