8.22 今日头条笔试

这次套路深啊,怎么还有改错题!。

上来看题,每个题目的输入数据都很大,果断上scanf,printf, 千万不能用cin,cout

1. 右上角的点,我的思路是先对每一行去重(题目好像说没有重的点耶!),每一行只有最右边的点才是候选点,然后对这些候选点按照y坐标,从大到小访问,要求相应的x是严格递增的,最后打印输出。

 1 #include<bits/stdc++.h>
 2 #define pb push_back
 3 typedef long long ll;
 4 using namespace std;
 5 typedef pair<int, int> pii;
 6 const int maxn = 1e3 + 10;
 7 int n;
 8 void solve() {
 9     map<int, int> ma;
10     scanf("%d", &n);
11     int x, y;
12     for (int i = 0; i < n; i++) {
13         scanf("%d%d", &x, &y);
14         if(ma.count(y)) {
15             ma[y] = max(ma[y], x);
16         } else ma[y] = x;
17     }
18     vector<pii> res;
19     auto it = ma.rbegin();
20     x = it->second - 1;
21     //cout << it->first <<endl;
22     while(it != ma.rend()) {
23         if(it->second > x) {
24             res.pb({it->second, it->first});
25             x = it->second;
26         }
27         it++;
28     }
29     for (pii t : res) {
30      printf("%d %d\n", t.first, t.second);
31     }
32 }
33 
34 int main() {
35     freopen("test.in", "r", stdin);
36     //freopen("test.out", "w", stdout);
37     solve();
38     return 0;
39 }
View Code

2. 我认为是分治, 首先考虑数组的最小值,哪些区间可以取到取小值,取到最小值,使得结果最大,当然是和最大,那就是全部的数,接下来这个最小值就可以不考虑了,分别对左半和右半重复上面处理。

#include<bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = 5e5 + 10;

int n;
ll a[maxn];
ll s[maxn];
ll f(int x, int y) {
    return s[y] - s[x - 1];
}
ll res = 0;
void work(int x, int y) {
    if(x > y) return;
    if(x == y) {
        res = max(res, a[x] * a[x]);
        return;
    }
    int p = x;
    for (int i = x; i <= y; i++) {
        if(a[i] < a[p]) {
            p = i;
        }
    }
    res = max(res, a[p] * f(x, y));
    work(x, p - 1);
    work(p + 1, y);
}
void solve() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
        s[i] = s[i - 1] + a[i];
    }
    work(1, n);
    printf("%lld\n", res);
}

int main() {
    freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    solve();
    return 0;
}

3. 题目描述的挺复杂,就是多个角度的优先队列,然后就试了试刚学习的函数类(仿函数,函数对象,函数指针),以及lambda表达式,写了一下。

最后过了80%, 我的是按时间模拟的,题目的范围是【1,3000】,我的for循环是1-3000,突然想到有些任务可能到3000的时候一直没有程序员空闲,所以for循环至少要到6000才行,这样才能ac吧。

感觉模拟到6000也不行。应该是任务队列判空为止才行。

 1 #include<bits/stdc++.h>
 2 #define pb push_back
 3 typedef long long ll;
 4 using namespace std;
 5 typedef pair<int, int> pii;
 6 const int maxn = 3e3 + 10;
 7 struct node {
 8     int id, p, s, pr, t;
 9 };
10 int n, m, p;
11 node a[maxn];
12 //这里扩大范围
13 int f[maxn * 2];
14 int res[maxn];
15 class cmp {
16 public:
17     bool operator()(const node&x, const node&y) {
18         if(x.pr == y.pr) {
19             if(x.t == y.t) {
20                 return x.s < y.s;
21             } else {
22                 return x.t < y.t;
23             }
24         } else {
25             return x.pr > y.pr;
26         }
27     }
28 };
29 set<node, cmp> data[maxn];
30 void solve() {
31     int x, y, x1, y1;
32     scanf("%d%d%d", &n, &m, &p);
33     for (int i = 1; i <= p; i++) {
34         scanf("%d%d%d%d", &x, &y, &x1, &y1);
35         a[i] = {i, x, y, x1, y1};
36     }
37     sort(a + 1, a + p + 1, [](const node&x, const node&y)->bool{return x.s < y.s;});
38     int cur = 0;
39     f[1] = m;
40     set<int> se;
41     x = 1;
42     int cnt = 0;
43     //这里应该模拟到6000, 保证所有的任务都有机会执行,或者更大。
44     for (int i = 1; i <= 3000; i++) {
45         cur += f[i];
46         while(x <= p) {
47             //cout << x << endl;
48             if(a[x].s == i) {
49                 data[a[x].p ].insert(a[x]);
50                 //cout << "asd " << a[x].id << endl;
51                 x++;
52                 cnt++;
53             } else break;
54         }
55         if(cur <= 0 || cnt == 0) continue;
56         int t = cur;
57 
58         for (int j = 0; j < t; j++) {
59             int id = -1;
60             int ti = 0;
61             for (int k = 1; k <= n; k++) {
62                 if(data[k].size() == 0)
63                     continue;
64                 else {
65                    // cout << k << " asd " << (data[k].begin())->t << endl;
66                     if(id == -1 || (data[k].begin())->t < ti) {
67                     id = k;
68                     ti = (data[k].begin())->t;
69                 }}
70             }
71             //cout << id << " " << ti << endl;
72             cur--;
73             cnt--;
74             node nd = *data[id].begin();
75             data[id].erase(data[id].begin());
76             res[nd.id] = i + nd.t;
77             f[i + nd.t]++;
78 
79             if(cnt <= 0 || cur <= 0) break;
80         }
81 
82     }
83     for (int i = 1; i <= p; i++)
84         printf("%d\n", res[i]);
85 }
86 
87 int main() {
88     freopen("test.in", "r", stdin);
89     //freopen("test.out", "w", stdout);
90     solve();
91     return 0;
92 }

 

转载于:https://www.cnblogs.com/y119777/p/7420563.html

本项目是一个基于SSM(Spring+SpringMVC+MyBatis)框架和Vue.js前端技术的家教平台系统。该系统旨在为家教和学生提供一个便捷、高效的在线交流和预约平台,涵盖了从用户注册登录、个人信息管理、课程发布与搜索、预约与取消预约、评价反馈等一系列功能。 在后台管理方面,系统提供了管理员对用户信息、课程信息、预约记录等进行管理的功能,确保平台的正常运行和数据的准确性。通过Spring框架的依赖注入和AOP特性,实现了业务逻辑的清晰分离和高效处理;SpringMVC则负责处理前端请求和响应,提供友好的用户界面;MyBatis作为ORM框架,简化了数据库操作,提高了数据访问的效率和安全性。 前端部分采用Vue.js框架,结合Vue Router进行页面路由管理,Axios进行HTTP请求,实现了前后端分离的开发模式。Vue.js的组件化开发和响应式数据绑定特性,使得前端页面更加动态和交互性强,提升了用户体验。 数据库设计采用了MySQL,存储了用户信息、课程信息、预约记录等核心数据。通过合理的数据库表结构和索引设计,保证了系统的高效运行和数据的一致性。 该项目不仅适合计算机相关专业的毕设学生参考和学习,也适合Java学习者进行项目实战练习。通过对该项目的深入理解和二次开发,可以实现更多个性化功能,进一步提升技术水平和实践能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值