几个易错点

1.数据范围一定要开大,一般多开10个或者5个。

2. 从经常写 int a[n], 然后访问a[n], 这显然会下标越界。

3. 浮点数,无法精确的比较,等于,大于,小于, 都需要使用eps, 这个坑以前不怎么遇到。如果能用int, 就能免除浮点数的精度影响。

4. unsigned int 和int的比较, 尤其是这样:你用有一个vector的size跟负数进行比较,这样显然会出错, 会把负数当做无符号数字进行转化,然后比较,就会出错。这应该算隐式转换的坑吧。

1. https://hihocoder.com/problemset/problem/1571?sid=1170501

每个插槽无关,我以为是背包,但是数据很大,m=1e4, k = 1e5, 结果太大,最后看答案是贪心。每个插槽对于非高级武器,就是从高到低选取相应个数,对于

高级武器,由于总个数的限制,所以计算对相应槽位的贡献,然后贪心的选取最大的k个。这类题目还是不怎么会做。

 #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, m, k;
struct node {
int v, p, t;
bool operator<(const node&x) const {
return v > x.v;
}
};
node a[maxn];
vector<int> e[maxn];
int c[maxn];
vector<int> jar;
void solve() {
scanf("%d%d%d", &n, &m, &k);
int x, y, z;
for (int i = ; i < n; i++) {
scanf("%d%d%d", &x, &y, &z);
a[i] = {x, y, z};
}
sort(a, a + n);
for (int i = ; i <= m; i++) {
scanf("%d", &c[i]);
e[i].clear();
}
ll res = ;
for (int i = ; i < n; i++) {
if(a[i].t) continue;
if(e[a[i].p ].size() < c[a[i].p ]) {
e[a[i].p ].pb(a[i].v);
res += a[i].v;
}
}
jar.clear();
for (int i = ; i < n; i++) {
if(a[i].t == ) continue;
if((int)e[a[i].p ].size() < c[a[i].p ]) {
jar.pb(a[i].v);
} else if(c[a[i].p ] > ){
jar.pb(a[i].v - e[a[i].p ][c[a[i].p ] - ]);
}
c[a[i].p ]--;
}
sort(jar.begin(), jar.end(), greater<int>());
for (int i = ; i < k && i < jar.size(); i++) {
if(jar[i] <= ) break;
res += jar[i];
}
printf("%lld\n", res); } int main() {
//freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
int _;
scanf("%d", &_);
while(_--)
solve();
return ;
}

2. https://hihocoder.com/problemset/problem/1561?sid=1171714

并查集维护集合,set维护顺序,关键是对边权从小到大遍历进行处理。没有做出来。

 #include<bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = 2e5 + ;
int f[maxn], sz[maxn]; int fd(int x) {
if(x == f[x]) return x;
return f[x] = fd(f[x]);
}
void un(int x, int y) {
if(sz[x] <= sz[y]) {
f[x] = y;
sz[y] += sz[x];
} else {
f[y] = x;
sz[x] += sz[y];
}
}
struct node {
int x, y, v, id;
bool operator<(const node&t)const {
return v < t.v;
}
};
node a[maxn];
int n, m;
pii res[maxn];
set<int> se[maxn];
void init(int n) {
for (int i = ; i <= n; i++) f[i] = i,sz[i] = , se[i].insert(i);
}
void solve() { scanf("%d%d", &n, &m);
init(n);
int x, y, v;
for (int i = ; i < m; i++) {
scanf("%d%d%d", &x, &y, &v);
a[i] = {x, y, v, i};
}
sort(a, a + m);
for (int i = ; i < m; i++) {
x = fd(a[i].x);
y = fd(a[i].y);
//cout << x << " " << y << endl;
if(x != y) {
int t1 = *se[x].rbegin(), t2 = *se[y].rbegin();
if(t1 > t2) {
res[a[i].id ] = {t2, *se[x].lower_bound(t2)};
} else {
res[a[i].id ] = {t1, *se[y].lower_bound(t1)};
}
if(sz[x] >= sz[y]) {
f[y] = x; sz[x] += sz[y];
se[x].insert(se[y].begin(), se[y].end());
} else {
f[x] = y; sz[y] += sz[x];
se[y].insert(se[x].begin(), se[x].end());
}
} else {
res[a[i].id ] = {,};
}
}
for (int i = ; i < m; i++)
printf("%d %d\n", res[i].first, res[i].second);
} int main() {
//freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
solve();
return ;
}

3. https://hihocoder.com/problemset/problem/1145?sid=1171476

很早的一个题目,我只会使用树状数组离线查询, 不知道线段树怎么在线查询,这个需要好好学习一下。

 #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, m;
vector<int> e[maxn];
int f[maxn];
int lb(int x) {
return x & -x;
}
void up(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;
}
vector<pii> a[maxn];
int res[maxn];
void solve() {
scanf("%d%d", &n, &m);
int x, y;
for (int i = ; i < n; i++) {
scanf("%d%d", &x, &y);
if(x > y) swap(x, y);
e[x].pb(y);
}
for (int i = ; i <= m; i++) {
scanf("%d%d", &x, &y);
a[x].pb({y, i});
}
for (int i = ; i >= ; i--) {
for (int u : e[i]) {
up(u);
}
for (pii t : a[i]) {
res[t.second] = (t.first - i + ) - ask(t.first);
}
}
for (int i = ; i <= m; i++)
printf("%d\n", res[i]);
} int main() {
//freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
solve();
return ;
}

最近几道hihocode不会做的题目的更多相关文章

  1. 几道leetcode不会做的题目

    1.set没有back()函数,今天想到用这个,才发现没有. 2. tuple的initialize_list construct好像不能使用,其实之前没使用过tuple,都是pair,复杂一点的自己 ...

  2. 几道hihocoder不会做的题

    1.https://hihocoder.com/problemset/problem/1433?sid=970287 boarding passes,不会做,看的别人的代码,现在还不是很理解. 2.  ...

  3. 刷完一千道java笔试题的常见题目分析

    java基础刷题遇到的最常见问题 可以先看一下这位博主整理的java面试题(很详细,我看了好几遍了):https://blog.csdn.net/ThinkWon/article/details/10 ...

  4. 要做的题目-要用到hadoop资源

    关于项目,我出两个练手题目: 一.多机数据处理.有 10 台机器,每台机器上保存着 10 亿个 64-bit 整数(不一定刚好 10 亿个,可能有上下几千万的浮动),一共约 100 亿个整数(其实一共 ...

  5. hihocoder #1039 : 字符消除 ( 字符串处理类 ) 好久之前做的题目,具体的算法代码中阅读吧

    #1039 : 字符消除 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi最近在玩一个字符消除游戏.给定一个只包含大写字母"ABC"的字符串s,消 ...

  6. Python练习题中做错题目

    1,一下代码执行的结果为 a = b = "julyedu.com" a = 'AI 教育' print(b) 答案: julyedu.com 要点: 在python中, 不可变对 ...

  7. [小结] 中山纪念中学2018暑期训练小结(划掉)(颓废记)-Day10

    [小结] 中山纪念中学2018暑期训练小结(划掉)(颓废记)-Day10 各位看众朋友们,你们好,今天是2018年08月14日,星期二,农历七月初四,欢迎阅看今天的颓废联编节目 最近发生的灵异事件有 ...

  8. 8.11zju集训日记

    今天的比赛打得很不好,前一个小时的看的题目都非常难,没有做出题目,中期看到两道题,一道题是我读题,金大佬solo的,另外一道题是金大佬读题,写了代码但wa了,然后我和zz找bug,最后发现答案的范围是 ...

  9. [日记&做题记录]-Noip2016提高组复赛 倒数十天

    写这篇博客的时候有点激动 为了让自己不颓 还是写写日记 存存模板 Nov.8 2016 今天早上买了两个蛋挞 吃了一个 然后就做数论(前天晚上还是想放弃数论 但是昨天被数论虐了 woc noip模拟赛 ...

随机推荐

  1. 洛谷 1541 NOIp2010提高组 乌龟棋

    [题解] 很容易想到这是一个DP,f[i][j][k][l]表示4种卡片分别用了多少张,那么转移方程就是f[i][j][k][l]=Max(f[i-1][j][k][l],f[i][j-1][k][l ...

  2. 【Codeforces 1034A】Enlarge GCD

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 设原来n个数字的gcd为g 减少某些数字之后 新的gcd肯定是g的倍数 即gx 我们可以枚举这个x值(x>=2) 看看原来的数字里面有多 ...

  3. 【Codeforces 466B】Wonder Room

    [链接] 我是链接,点我呀:) [题意] 让你把长为a,宽为b的房间扩大(长和宽都能扩大). 使得它的面积达到6*n 问你最小的能满足要求的面积是多少 输出对应的a和b [题解] 假设a< b ...

  4. ios 7以后 隐藏顶部状态栏

    iOS 7 以后,之前隐藏顶部状态栏的方法都已经失效.以下介绍的方法是全部兼容的. 修改xode工程里的 Info.plist 增加 Status bar is initially hidden一行, ...

  5. 学习MongoDB--(5-2):索引(查看索引的使用,管理索引)

    前一篇简单介绍了索引,并给出了基本的索引使用,这一次,我们进一步说一下MongoDB中的索引,包括如何查看查询是否走索引,如何管理索引和地理空间索引等. [使用explain和hint] 前面讲高级查 ...

  6. golang中channels的本质详解,经典!

    原文:https://www.goinggo.net/2014/02/the-nature-of-channels-in-go.html The Nature Of Channels In Go 这篇 ...

  7. 交换机tagged与untagged的关系深入探讨

    端口接收数据时: 如果端口是tagged方式,当数据包本身不包含VLAN的话,输入的数据包就加上该缺省vlan:如果数据包本身已经包含了VLAN,那么就不再添加. 如果是untagged方式,输入的数 ...

  8. group & user

    例子 groupadd  test   创建test用户组 useradd  user1   创建user1用户 passwd   user1   设置user1的密码 useradd  user2  ...

  9. gem5: 使用ruby memory system中的mesh结构 出现AssertionError错误

    问题:在使用ruby memory system中的mesh结构測试时,出现例如以下错误: Traceback (most recent call last): File "<stri ...

  10. Wireshark 抓包遇到 you don’t have permission to capture on that device mac 错误的解决方案

    Wireshark 抓包遇到 you don’t have permission to capture on that device mac 错误的解决方案 上次有篇博客讲了如何利用wireshark ...