[hihocoder][Offer收割]编程练习赛58
最大的K-偏差排列
每次取可选范围里的最大的数字,如果最左侧的数字还没有使用就直接使用最左侧的数字
#pragma comment(linker, "/STACK:102400000,102400000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<functional>
#include<math.h>
//#include<bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
int n, k;
bool f[];
cin >> n >> k;
memset(f, false, sizeof(f));
for (int i = ; i <= n; i++) {
if (i - k > && !f[i - k]) {
f[i - k] = true;
cout << i - k << ' ';
continue;
}
for (int j = i + k; j > i - k; j--) {
if (j > n || j < ) continue;
if (!f[j]) {
f[j] = true;
cout << j << ' ';
break;
}
}
}
return ;
}
孤独的字符
枚举每个字符,计算它是一个孤独字符时包含它的区间有多少个
#pragma comment(linker, "/STACK:102400000,102400000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<functional>
#include<math.h>
//#include<bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} string s;
int pre[], nex[], last[]; int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
cin >> s;
int n = s.length();
memset(last, -, sizeof(last));
for (int i = ; i < n; i++) {
pre[i] = last[s[i]];
nex[i] = n;
if (last[s[i]] >= ) nex[pre[i]] = i;
last[s[i]] = i;
}
lint ans = ;
for (int i = ; i < n; i++) {
ans += 1LL * (nex[i] - i) * (i - pre[i]);
}
cout << ans << endl;
return ;
}
秋天来了
这题有问题,都说了l是唯一最高完了样例好几个最高???最高的还能看到别人???
Nim森林
这题跟这棵树没啥关系。两个回合以后,是一个典型的反nim游戏,先手获胜的条件为:1)所有堆的石子个数为1,且NIM_sum=0或2)至少有一堆的石子个数大于1,且 NIM_sum≠0。第一种获胜情况是所有堆狮子个数为1且有偶数堆,这种情况是不可能达到的。经过第一回合操作后,只要有石子数为1的石堆,B都可以拿完多于1的石堆且剩下奇数个石子数为1的石堆,所以只需考虑第二种情况(且所有石堆石子数大于1)。按代价从大到小的顺序添加各个石堆的石子数到线性基中,成功添加进去的就是第二回合给B留下的。
#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
using LD = long double;
const LL INF = 0x3f3f3f3f;
const LL mod = 1e9 + ; template <typename T>
struct LnBase{
int sz, szc;
T *x;
int *y;
LnBase (){x = ; sz = sizeof(T) << ; szc = -; resize(sz);}
void resize(int size){
sz = size; if(!x) delete(x); x = new T[sz + ]; y = new int[sz + ];
memset(x, , sz * sizeof(T)); memset(y, , sz << );
}
T operator[](int h){return x[h];}
int add(T v){
for(int i = sz - ; i >= ; i--)
if(v & (T) << i){if(!x[i]){x[i] = v; szc = -; return i;} v ^= x[i];}
return -;
}
int find(T v){
for(int i = sz - ; i >= ; i--){
if(v & (T) << i && x[i]) v ^= x[i]; if(!v) return ;}
return ;
}
T Max(){
T s = ;
for(int i = sz - ; i >= ; i--){if((s ^ x[i]) > s) s ^= x[i];}
return s;
}
T Min(){
for(int i = ; i < sz; i++) if(x[i]) return x[i];
return -;
}
void Canonicity(){
int i, j;
for(i = sz - ; i > ; i--)
for(j = i - ; j >= ; j--) if(x[i] & (T) << j) x[i] ^= x[j];
for(szc = i = ; i < sz; i++) if(x[i]) y[szc++] = i;
}
T Kth(long long K){
if(szc < ) Canonicity(); if(K >= 1ll << szc) return -; T s = ;
for(int i = szc - ; i >= ; i--) if(K & 1ll << i) s ^= x[y[i]];
return s;
}
}; struct node {
__int128 a, t;
bool operator<(const node &e) const { return t > e.t; }
};
int main() {
ios::sync_with_stdio();
cin.tie();
int n;
cin >> n;
n--;
vector<node> a(n);
for (auto &i : a) {
LL u, v, a, t;
cin >> u >> v >> a >> t;
i.a = a;
i.t = u ^ v ^ t;
}
sort(a.begin(), a.end());
int flag = ;
__int128 ans = , sum = ;
LnBase<__int128> b;
for (auto& s : a) {
sum += s.t;
if (s.a == ) continue;
flag = ;
if (b.add(s.a) != -) ans += s.t;
}
if (flag) cout << "No\n";
else {
ans = sum - ans;
string s = "";
while (ans) {
s += '' + ans % ;
ans /= ;
}
if (s == "") s = "";
reverse(s.begin(), s.end());
cout << s << '\n';
}
}
[hihocoder][Offer收割]编程练习赛58的更多相关文章
- hihocoder [Offer收割]编程练习赛4
描述 最近天气炎热,小Ho天天宅在家里叫外卖.他常吃的一家餐馆一共有N道菜品,价格分别是A1, A2, ... AN元.并且如果消费总计满X元,还能享受优惠.小Ho是一个不薅羊毛不舒服斯基的人,他希望 ...
- hihocoder [Offer收割]编程练习赛61
[Offer收割]编程练习赛61 A:最小排列 给定一个长度为m的序列b[1..m],再给定一个n,求一个字典序最小的1~n的排列A,使得b是A的子序列. 贪心即可,b是A的子序列,把不在b中的元素, ...
- ACM学习历程—Hihocoder [Offer收割]编程练习赛1
比赛链接:http://hihocoder.com/contest/hihointerview3/problem/1 大概有一个月没怎么打算法了.这一场的前一场BC,也打的不是很好.本来Div1的A和 ...
- hihocoder offer收割编程练习赛8 C 数组分拆
思路:(引自bfsoyc的回答:http://hihocoder.com/discuss/question/4160) 动态规划.状态dp[i]表示 前i个数的合法的方案数,转移是 dp[i] = s ...
- hihocoder [Offer收割]编程练习赛18 C 最美和弦(dp)
题目链接:http://hihocoder.com/problemset/problem/1532 题解:一道基础的dp,设dp[i][j][k][l]表示处理到第几个数,当前是哪个和弦错了几次初始x ...
- hihoCoder [Offer收割]编程练习赛3 D子矩阵求和
子矩阵求和 http://hihocoder.com/discuss/question/3005 声明一下: n是和x一起的,m是和y一起的 x是横着的,y是纵着的,x往右为正,y往下为正 (非常反常 ...
- hihocoder [Offer收割]编程练习赛52 D 部门聚会
看了题目的讨论才会做的 首先一点,算每条边(u, v)对于n*(n+1)/2种[l, r]组合的贡献 正着算不如反着算 哪些[l, r]的组合没有包含这条边(u, v)呢 这个很好算 只需要统计u这半 ...
- hihocoder [Offer收割]编程练习赛14
A.小Hi和小Ho的礼物 谜之第1题,明明是第1题AC率比C还要低.题目是求在n个不同重量袋子选4袋,2袋给A,2袋给B,使2人获得重量相同,求问方案数. 我也是一脸懵b...o(n2)暴力枚举发现把 ...
- hihocoder [Offer收割]编程练习赛8
第一次做这种比赛,被自己坑的好惨... A.这道题的关键其实是如果有k和n满足kD+F>nL>kD则不能走无限远,分支看似难整理,其实比较简单,F>L根本就不用算了,明摆着就是Bsi ...
随机推荐
- Shiro-工作流程
[与Web集成] 1.Shiro 提供了与 Web 集成的支持,其通过一个ShiroFilter 入口来拦截需要安全控制的URL,然后进行相应的控制. 2.ShiroFilter 类似于如 Strut ...
- 数据库——mysql如何获取当前时间---https://www.cnblogs.com/Chenshuai7/p/5136469.html
数据库——mysql如何获取当前时间 1.1 获得当前日期+时间(date + time)函数:now() -------https://www.cnblogs.com/Chenshuai7/p/51 ...
- js 发布订阅模式
//发布订阅模式 class EventEmiter{ constructor(){ //维护一个对象 this._events={ } } on(eventName,callback){ if( t ...
- Happy 2006 欧几里得定理
Happy 2006 Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 11956 Accepted: 4224 Descr ...
- 一篮子苹果,每天吃一半多一个吃,第十天吃一半多一个后就剩余一个,求一共多少个苹果,JAVA版
/** * @author xuzhu **/public class TestApple { public static void main(String[] args) { int days = ...
- tomcat上传图片失败
今天,突然遇到个奇怪的问题,tomcat上传图片时好时坏,经查线上四台服务有一台服务器硬盘满了. 解决一下硬盘空间的问题,有好使了,那么图片上传通过流写到远程对象存储服务中,并没有落盘和硬盘满有哪些关 ...
- JSP计数器
1.JSP弥补了servlet页面显示的不足:jsp运行时候需要转化为servlet,本质上就是servlet:tomcat下的work目录下有jsp的servlet和对应的class文件;下次再调用 ...
- [Vue @Component] Switch Between Vue Components with Dynamic Components
A common scenario is to present different components based on the state of the application. Dynamic ...
- python练习-跳出多层循环和购物车
跳出多层循环:三层循环,最里层直接跳出3层 在Python中,函数运行到return这一句就会停止,因此可以利用这一特性,将功能写成函数,终止多重循环 def work(): for i in ran ...
- Centos 7 Apache编译安装
1.安装apache ./configure --prefix=/usr/local/apache2 --enable-rewrite --enable-so --enable-headers --e ...