5.27 indeed 第三次网测
1. 第一题, 没有看
2. 暴力枚举。每一个部分全排列, 然后求出最大的请求数。
#include<bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e3 + ; int n;
int t;
vector<int> a[];
int res = ;
void work(int p, int s, int c) {
if(p >= t) {
res = max(res, c);
return;
} do {
int st = s;
int ct = c;
for (int i = ; i < ; i++) {
if(st >= a[p][i]) {
st -= a[p][i];
ct++;
}
}
work(p + , st, ct);
} while(next_permutation(a[p].begin(), a[p].end()));
}
void solve() {
cin >> n >> t;
int x;
for (int i = ; i < t; i++) {
for (int j = ; j < ; j++) {
cin >> x;
a[i].pb(x);
}
sort(a[i].begin(), a[i].end());
}
work(, 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 ;
}
3. 二叉树, 求路径, 其实很简单, 每个节点只有一个父亲, 然后记录是左还是右, 从目标节点向上走到根节点即可。或者是dfs也可以。
#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][];
int k;
vector<char> p;
bool work(int x) {
if(x == k) return ;
if(a[x][]) {
if(work(a[x][])) {
p.pb('L');
return ;
}
}
if(a[x][]) {
if(work(a[x][])) {
p.pb('R');
return ;
}
}
return ;
}
void solve() {
scanf("%d%d", &n, &k);
int x, y;
for (int i = ; i <= n; i++) {
scanf("%d%d", &x, &y);
a[i][] = x; a[i][] = y;
} work();
reverse(p.begin(), p.end());
for (char c : p)
printf("%c", c);
printf("\n");
} int main() {
freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
ios::sync_with_stdio();
cin.tie(); cout.tie();
solve();
return ;
}
4. 这个题,刚开始,我以为是找环,然后是环的长度,对每一个节点,用步数求环的余数即可,但是一些节点不在环上,但是他可以到达环,这些点比较难处理。
后来,就想到,我把每一步走到哪里全记录下来就可以了,然后利用lca的数据结构,父亲的父亲, 然后对每一个点的步数进行二分,就可以得到最后的答案了。
#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];
int dp[maxn][];
ll ti;
void solve() {
scanf("%d%lld", &n, &ti);
//ti--;
for (int i = ; i <= n; i++) {
scanf("%d", &a[i]);
dp[i][] = a[i];
//cout << dp[i][0] << endl;
}
for (int j = ; j < ; j++) {
for (int i = ; i <= n; i++) {
dp[i][j] = dp[dp[i][j - ] ][j - ];
}
}
for (int i = ; i <= n; i++) {
int cur = i;
for (int j = ; j >= ; j--) {
if(ti & (1ll << j)) {
cur = dp[cur][j];
//cout << i << " " << j << " " << cur << endl;
} }
printf("%d\n", cur);
} } int main() {
freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
ios::sync_with_stdio();
cin.tie(); cout.tie();
solve();
return ;
}
5.27 indeed 第三次网测的更多相关文章
- indeed2017校招在线编程题(网测)三
A. Calculate Sequence 分析:就是斐波那契递推公式,但是初始值是指定的,只用求第10个数,数据范围和复杂度都比较小,直接写. B. 忘了叫啥了. 就是有a-j十个字符组成的字符串, ...
- 【j2ee spring】27、巴巴荆楚网-整合hibernate4+spring4(2)
巴巴荆楚网-整合hibernate4+spring4(2) 1.图文项目 2.首先我们引入对应的jar包 这里用的是oracle 11g,所以我们使用的数据库连接jar包是ojdbc6, 的区别就是支 ...
- 2014-CVTE网测部分软件技术测试题及答案
1.叉树的先序遍历序列和后序遍历序列正好相反,则该二叉树满足的条件是(D) A.空或只有一个结点 B.高度等于其结点数 C.该二叉树是完全二叉树 D.所有结点无右孩子 应该是二叉树的每个结点都只有一个 ...
- indeed 5.13 第二次网测
题目描述,我找不见了,大概写一下想法和代码吧. 1. 没有看 2. 由于数据范围很小,就是简单的枚举,求全排列,然后更新答案. #include<bits/stdc++.h> #defin ...
- 商业模式(三):P2P网贷平台,毛利润测算
之前谈到P2P网贷平台,主要的收入就是"息差". 一直以来,想详细写点P2P平台的收益到底如何的,奈何自己感觉收入上的点不算多,对财务这种核心机密了解的也不多,一直没 ...
- charles功能(三)弱网测试(模拟超慢网速,会导致接口数据返回超时的那种慢)
模拟超慢网速(会导致接口数据返回超时的那种...) 设置带宽和延迟时间(毫秒) 注:可以根据下图中的翻译体会下导致网络延迟的原因: 然后打开网页回变得非常满
- wap网测一道题目
1. 给定一个字符串s, 1 <= len(s) <= 3000, 定义odd palindrome string为长度为奇数的回文串, 求s中该奇回文串的个数. 比如axbcba , 结 ...
- wap 5.23 网测几道题目
1. n个犯人,m个省份, 如果相邻的2个犯人来自同一省份,则是不安全的,求不安全的个数. 正难则反,用全部的个数减去非法的个数,就是最后的答案. m^n - m * (m - 1) ^ (n - 1 ...
- indeed 4.22 第一次网测
1.第一题 没有看 2. 由于数据范围很小,所以每一层需要全排列,寻找最小的花费,然后所有层加起来就是最后的结果. #include<bits/stdc++.h> #define pb p ...
随机推荐
- Swift 3到5.1新特性整理
本文转载自:https://hicc.me/whats-new-in-swift-3-to-5-1/,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有. Hipo 2.0 重写从 Swif ...
- ubuntu14.04禁用USB外存储设备
ubuntu 14.04中禁用usb外存储设备: 在网上找了很多方法,大概都是下面的命令,而实际测试的时候没有什么作用. gsettings set org.gnome.desktop.media-h ...
- LIS(两种方法求最长上升子序列)
首先得明白一个概念:子序列不一定是连续的,可以是断开的. 有两种写法: 一.动态规划写法 复杂度:O(n^2) 代码: #include <iostream> #include <q ...
- 匈牙利算法求最大匹配(HDU-4185 Oil Skimming)
如下图:要求最多可以凑成多少对对象 大佬博客: https://blog.csdn.net/cillyb/article/details/55511666 https://blog.csdn.net/ ...
- Vue.js:使用vue-cli快速构建项目
vue-cli是什么? vue-cli 是vue.js的脚手架,用于自动生成vue.js模板工程的. vue-cli怎么使用? 安装vue-cli之前,需要先安装了vue和webpack,不知道怎么安 ...
- PAT 1104 Sum of Number Segments
Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For exam ...
- 【codeforces 755F】PolandBall and Gifts
[题目链接]:http://codeforces.com/contest/755/problem/F [题意] n个人; 计划是每个人都拿一个礼物来送给一个除了自己之外的人; 且如果一个人没有送出礼物 ...
- bupt summer training for 16 #2 ——计算几何
https://vjudge.net/contest/171368#overview A.一个签到题,用叉积来判断一个点在一条线的哪个方向 可以二分,数据范围允许暴力 #include <cst ...
- C#实现所有经典排序算法汇总
C#实现所有经典排序算法1.选择排序 class SelectionSorter { private int min; public void Sort(int[] arr) { ; i < a ...
- vs2010+cuda5.0+qt4.8
在进行CUDA处理的时候,总是在控制台程序下,于是就想要通过qt进行界面处理. 一开始先测试一下qt的环境,新建一个qt项目,不过在运行的时候提示平台不对,换成64位 出现 这个是qt的版本问题,在右 ...