SnackDown Online Qualifier 2017
好久没做题了,然后就想着随便做一个。无奈cf都是晚上,然后就看见这个,随便做做。
资格赛,只要做出来1题就行了,4天的时间。
1. 水题
#include <iostream>
#include <stdio.h> using namespace std; int n;
string s;
void yes() {
cout << "Valid" << endl;
}
void no() {
cout << "Invalid" << endl;
}
void solve() {
cin >> n >> s;
int t = ;
for (char c : s) {
if(c == 'H') {
if(t == ) {
t = ;
} else {
no();
return;
}
} else if(c == 'T') {
if(t == ) {
t = ;
} else {
no();
return;
}
}
}
if(t != ) no();
else yes();
} int main() {
//freopen("test.in", "r", stdin);
int _;
cin >> _;
while(_--)
solve();
return ;
}
2. 就是 1, 2,3,。。,3,2,1,必须是奇数个。
#include<bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e2 + ; int n;
int a[maxn];
void yes() {cout << "yes" << endl;}
void no() {cout << "no" << endl;}
void solve() {
cin >> n;
for (int i = ; i <= n; i++) cin >> a[i];
if(n % == ) {
no(); return;
}
for (int i = ; i <= n / + ; i++) {
if(i != a[i] || a[i] != a[ + n - i]) {
no(); return;
}
}
yes();
} int main() {
// freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
ios::sync_with_stdio();
cin.tie(); cout.tie();
int _;
cin >> _;
while(_--)
solve();
return ;
}
3. 这个题,我写的很麻烦, 上来先判断线段的类型,有三种,点,水平和垂直,然后每2种进行考虑。
只要一个是点, 就判断这个点是不是在另一个线段上。
2条线段类型相同, 都是水平或者垂直, 这个时候, 必须共线才满足条件,否则不满足。
2条线段类型不同,这个时候,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 type, mx, ma, mb;
void work(int x, int y, int a, int b) {
type = mx = mb = -;
if(x == a && y == b) {
type = ;
ma = x; mb = y;
return;
}
if(x == a) {
type = ;
mx = x;
ma = min(y, b);
mb = max(y, b);
} else {
type = ;
mx = y;
ma = min(x, a);
mb = max(x, a);
}
}
void yes() {
cout << "yes" << endl;
}
void no() {
cout << "no" << endl;
}
void solve() {
int x, y, a, b;
cin >> x >> y >> a >> b;
work(x, y, a, b);
int xt = type, xx = mx, xa = ma, xb = mb;
cin >> x >> y >> a >> b;
work(x, y, a, b);
//cout << xt << " " << type << endl;
if(xt == type) {
if(xt == ) {
if(xa == ma && xb == mb) {
yes();
} else {
no();
}
return;
}
if(xx != mx) {
no();
return;
}
if(xa > mb || ma > xb) {
no();
return;
}
yes();
} else {
if(xt == ) {
if((xa == mx && xb >= ma && xb <= mb) || (xb == mx && xa >= ma && xa <= mb)) {
yes(); } else {
no();
}
return;
}
if(type == ) {
if((ma == xx && mb >= xa && mb <= xb) || (mb == xx && ma >= xa && ma <= xb)) {
yes();
} else no();
return;
}
if((xx == ma || xx == mb) && (mx == xa || mx == xb)) {
yes();
return;
}
no();
}
} int main() {
//freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
ios::sync_with_stdio();
cin.tie(); cout.tie();
int _; cin >> _;
while(_--)
solve();
return ;
}
4. 大蛇吃小蛇,先从小到大排序,然后对于一次查询,大于等于l的都是满足要求的, 这个是二分, 然后判断剩下的最多能凑成几条蛇。
剩下的能凑成几条,也是判断一种状况, 左边的蛇都被吃掉,右边的蛇变长成l,看需要的个数是否是左边的个数, 这个过程也是二分,然后就完了。
#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, q;
int a[maxn];
ll s[maxn];
ll work(int x, int y) {
return s[y] - s[x - ];
}
void solve() {
memset(a, , sizeof a);
memset(s, , sizeof s);
scanf("%d%d", &n, &q);
for (int i = ; i <= n; i++) {
scanf("%d", &a[i]);
//s[i] = s[i - 1] + a[i];
}
sort(a + , a + n + );
for (int i = ; i <= n; i++)
s[i] = s[i - ] + a[i];
int k;
while(q--) {
scanf("%d", &k);
int t = lower_bound(a + , a + n + , k) - a;
//cout << t <<endl;
int res = n + - t;
int left = , right = t - , ed = t - ;
while(left < right) {
int mid = (left + right) / ;
ll st = 1ll * (ed - mid) * k - work(mid + , ed);
//cout << st << " " << mid << endl;
if(st > mid) {
left = mid + ;
} else right = mid;
//cout << left << " " << right << " " << mid << endl;
}
//cout << left << " " << right << endl;
if(left == right)
res += ed - left;
printf("%d\n", res);
}
} int main() {
//freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
int _;
scanf("%d", &_);
while(_--)
solve();
return ;
}
SnackDown Online Qualifier 2017的更多相关文章
- Bumped! 2017 ICPC North American Qualifier Contest (分层建图+dijstra)
题目描述 Peter returned from the recently held ACM ICPC World finals only to find that his return flight ...
- [codechef]SnackDown 2017 Online Elimination Round Prefix XOR
预处理后主席树维护 首先得出最后的答案为 \(\sum_{i=l}^{r}{min(right[i],r)-i+1}\) \(ri[i]\)表示i最远的上升序列(即代码中的f[i]) step1 那么 ...
- 2017,科学使用strace神器(附代码,举栗子)
我感到惊讶,都2017年了,几乎没有人知道他们可以使用strace的了解所有事情.它总是我拔出的第一个调试工具之一,因为它通常在我运行的Linux系统上可用,并且它可以用于解决各种各样的问题. 什么是 ...
- spring in action 学习笔记八:用@Primary 或者@Qualifier消除@Autowired引起的歧义现象
首先解释一下@Primary和@Qualifier这两个注解的意思:@Primary的意思是在众多相同的bean中,优先使用用@Primary注解的bean.而@Qualifier这个注解则指定某个b ...
- CI Weekly #10 | 2017 DevOps 趋势预测
2016 年的最后几个工作日,我们对 flow.ci Android & iOS 项目做了一些优化与修复: iOS 镜像 cocoapods 版本更新: fir iOS上传插件时间问题修复: ...
- 猖獗的假新闻:2017年1月1日起iOS的APP必须使用HTTPS
一.假新闻如此猖獗 刚才一位老同事 打电话问:我们公司还是用的HTTP,马上就到2017年了,提交AppStore会被拒绝,怎么办? 公司里已经有很多人问过这个问题,回答一下: HTTP还是可以正常提 ...
- iOS的ATS配置 - 2017年前ATS规定的适配
苹果规定 从2017年1月1日起,新提交的 app 不允许使用NSAllowsArbitraryLoads来绕过ATS(全称:App Transport Security)的限制. 以前为了能兼容ht ...
- 深入研究Visual studio 2017 RC新特性
在[Xamarin+Prism开发详解三:Visual studio 2017 RC初体验]中分享了Visual studio 2017RC的大致情况,同时也发现大家对新的Visual Studio很 ...
- Xamarin+Prism开发详解三:Visual studio 2017 RC初体验
Visual studio 2017 RC出来一段时间了,最近有时间就想安装试试,随带分享一下安装使用体验. 1,卸载visual studio 2015 虽然可以同时安装visual studio ...
随机推荐
- perf-perf stat用户层代码分析
perf_event 源码分析 前言 简单来说,perf是一种性能监测工具,它首先对通用处理器提供的performance counter进行编程,设定计数器阈值和事件,然后性能计数器就会在设定事件发 ...
- [转]linux内存管理源码分析 - 页框分配器
转自: http://www.cnblogs.com/tolimit/ 阅读之前,先敬原作者一杯! 分段和分页 先看一幅图 也就是我们实际中编码时遇到的内存地址并不是对应于实际内存上的地址,我们编码中 ...
- js 弹出div窗口 可移动 可关闭
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- js的一些工具类
//写入cookie function setCookie(name, value) { var Days = 30; //此 cookie 将被保存 30 天 var exp = n ...
- [SQL Service]从一张表取值更新另一张表字段
1. update table_A set table_A_column = ab.column from table_A aa left join table_B ab on aa.xx = ab ...
- JavaScript day2(变量)
变量(variable) 允许计算机以一种动态的形式来存储和操作数据,通过操作指向数据的指针而不是数据本身来避免了内存泄露,变量(Variable)的名字可以由数字.字母.$ 或者 _组成,但是不能包 ...
- Linux之日志管理
日志介绍日志配置日志管理远程日志基于MYSQL的日志 日志介绍日志:历史事件:时间,地点,人物,事件日志级别:事件的关键性程度,Loglevel系统日志服务:sysklogd :CentOS 5之前版 ...
- [网络收集]20190528华为数通网络工程师认证HCIA-VRP的操作指导思维导图
>> >0 VRP基础 >1 命令行基础 >2 文件系统基础 >3 VRP系统管理
- 清北学堂模拟赛d3t6 c
分析:比较神奇的一道题.要把树变成环肯定要先变成链,然后把链给拼接成环.接下来考虑一个脑洞大开的树形dp:设f[i][0]表示i不与父节点相连的链数,f[i][1]表示i与父节点相连的链数,先考虑怎么 ...
- CentOS的free命令
https://blog.csdn.net/for_tech/article/details/53044610 https://www.58jb.com/html/145.html