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. 离职 mark

    昨天(2019 年 5 月 17 日),从 离职. 从 2018 年 7 月 14 日早 10 点余分到 2019 年 5 月 17 日早 10 点余分,一共 308 天整.这就是我出学校的第一份工作 ...

  2. List lambda 排序

    Comparator<PromotionRule> comparator = Comparator.comparing(PromotionRule::getCreatedTime); pr ...

  3. 《编译原理》构造 LL(1) 分析表的步骤 - 例题解析

    <编译原理>构造 LL(1) 分析表的步骤 - 例题解析 易错点及扩展: 1.求每个产生式的 SELECT 集 2.注意区分是对谁 FIRST 集 FOLLOW 集 3.开始符号的 FOL ...

  4. 重载与重写的区别----https://blog.csdn.net/zhu_apollo/article/details/1852542

    重载 overloading        1) 方法重载是让类以统一的方式处理不同类型数据的一种手段.多个同名函数同时存在,具有不同的参数个数/类型.重载是一个类中多态性的一种表现.        ...

  5. codevs1127 接水问题

    题目描述 Description 学校里有一个水房,水房里一共装有m 个龙头可供同学们打开水,每个龙头每秒钟的供水量相等,均为1. 现在有n 名同学准备接水,他们的初始接水顺序已经确定.将这些同学按接 ...

  6. spring boot jpa 事务管理

    spring boot 对jpa的支持极为方便,基本上不需要作太多配置,只需要加上注解就能支持事务: @Controller @Transactional(rollbackOn = Exception ...

  7. loginitem

    + (BOOL) willStartAtLogin:(NSURL *)itemURL { Boolean foundIt=false; LSSharedFileListRef loginItems = ...

  8. 武大OJ 574. K-th smallest

    Description Give you a number S of length n,you can choose a position and remove the number on it.Af ...

  9. python列表可以加可以乘

    python列表可以加可以乘 list=['abcd',786,2.23,'runoob',70.2] tinylist = [123,'runoob'] print(list) print(list ...

  10. Ajax跨域、Json跨域、Socket跨域和Canvas跨域等同源策略限制的解决方法

    同源是指同样的协议.域名.port,三者都同样才属于同域.不符合上述定义的请求,则称为跨域. 相信每一个开发者都曾遇到过跨域请求的情况,尽管情况不一样,但问题的本质都能够归为浏览器出于安全考虑下的同源 ...