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 ...
随机推荐
- hdu 2084 数塔(简单dp)
题目 简单dp //简单的dp #include<stdio.h> #include<string.h> #include<algorithm> using nam ...
- 51nod1049 最大子段和【动态规划】
N个整数组成的序列a[1],a[2],a[3],-,a[n],求该序列如a[i]+a[i+1]+-+a[j]的连续子段和的最大值.当所给的整数均为负数时和为0. 例如:-2,11,-4,13,-5,- ...
- lua_note_01_lua介绍
1. lua 1. lua 1.1. lua介绍 1.2. Lua 特性 1.3. 特点 1.4. Lua 应用场景 1.5. 环境搭建 1.6. VS lua 1.1. lua介绍 Lua 是一种轻 ...
- i++与++i的区别及效率
i++与++i的区别及效率 先看看基本区别:i++ :先在i所在的表达式中使用i的当前值,后让i加1++i :让i先加1,然后在i所在的表达式中使用i的新值 看一些视频教程里面写for循环的时候都 ...
- Python 4 循环语句while
while [条件]: 条件这里满足布尔运算True则无限循环while里面代码. 固定条件的 基本的while循环, 如果if匹配那么 则执行打印登录成功,和break跳出整个循环, ...
- 【学QT】 3 - DEBUG集子
1. [root@localhost helloqt]# make g++ -Wl,-rpath,/usr/local/qt/lib -o cfconv .obj/main.o .obj/cfconv ...
- K - 贪心 基础
FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containi ...
- ubuntu 14.04升级PHP5.5.9 到5.6
升级的步骤:参考https://www.digitalocean.com/community/questions/how-to-upgrade-from-php-v-5-5-9-to-v-5-6 su ...
- android.os.TransactionTooLargeException
android.os.TransactionTooLargeException 今天开发过程共遇到问题,后台要反回一些表格,不是单纯的数据.就是有一些html标签的东西.错误的思路: 我得到数据后通过 ...
- Apache server配置
Apacheserver在我们生活中非经常常使用 今天给大家将一下mac 下apache server的配置 这对程序来说是必备技能之中的一个,假设我们在公司开发都是用的公司的server 将自己的代 ...