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 ...
随机推荐
- vue和iview中native点击事件修饰
在父组件中给子组件绑定一个原生的事件,就将子组件变成了普通的HTML标签,不加'. native'事件是无法触 在vue中使用iview的dropdownMenu 上单纯的@click也不生效,要写成 ...
- 【Apache Kafka】二、Kafka安装及简单示例
(一)Apache Kafka安装 1.安装环境与前提条件 安装环境:Ubuntu16.04 前提条件: ubuntu系统下安装好jdk 1.8以上版本,正确配置环境变量 ubuntu系统下安 ...
- for循环中索引值和取值的迷惑
利用for循环和range从100——10,倒序讲所有的偶数添加到一个新列表中,然后对列表的元素进行筛选,将能被4整除的数留下来. even = []for i in range(100,9,-1): ...
- Going Home HDU - 1533(最大费用最小流)
On a grid map there are n little men and n houses. In each unit time, every little man can move one ...
- python 未知
import timeimport requestsfrom bs4 import BeautifulSoupimport threading def format_str(s): return s. ...
- Spring MVC学习总结(9)——Spring MVC整合swagger自动生成api接口文档
Swagger 号称:世界最流行的API框架,官网:http://swagger.io/,Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总 ...
- 清北学堂模拟赛d3t4 a
分析:很水的一道题,就是用栈来看看是不是匹配就好了,只是最后没有判断栈是否为空而WA了一个点,以后做题要注意了. #include <bits/stdc++.h> using namesp ...
- Spring Boot访问mysql(JPA方式)最简单配置
0.先推荐一个工具--lombok,pom文件如下: <dependency> <groupId>org.projectlombok</groupId> <a ...
- printf 打印字符串的任意一部分
使用printf()函数打印字符串的任意部分,请看下例: <span style="font-size:16px;">#include <stdio.h> ...
- Ambari-部署常见问题
重新启动ambari-server端后调用install.start API后返回200 导致该问题的解决办法是server在启动后没有收到agent的心跳即没有与agent建立连接,在此时进行API ...