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 ...
随机推荐
- ionic 创建某个文件下的page
ionic g page 文件名 --pagesDir src/pages/about
- SqlServer Function
set quoted_identifier on; set ansi_nulls on; go create function [dbo].[Get_StrArrayStrOfIndex] ( @st ...
- swift-新手必看的基础部分
Swift 是一门开发 iOS, OS X 和 watchOS 应用的新语言.然而,如果你有 C 或者 Objective-C 开发经验的话,你会发现 Swift 的很多内容都是你熟悉的. 常量和变量 ...
- 名字竞技场 V3.0
更新内容 1.加入新boss,更高的难度. 2.支持组队模式勒! 3.针对大家反应的人物属性算法进行了修改,现在人物属性更多的取决于名字而不是随机数 4.用户界面优化 INF.代码拿走赞留下,不然你赢 ...
- [luogu1485 HNOI2009] 有趣的数列 (组合数学 卡特兰数)
传送门 Solution 卡特兰数 排队问题的简单变化 答案为\(C_{2n}^n \pmod p\) 由于没有逆元,只好用分解质因数,易证可以整除 Code //By Menteur_Hxy #in ...
- 53. Maximum Subarray(动态规划)
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- webpack-dev-server和webpack
指导小伙伴在webstorm+nodejs环境下新建项目时,小伙伴出现了一个很神奇的问题:没有执行webpack-dev-server情况下,即使执行npm init,也不会出现package.jso ...
- VS2017git 提交提示错误 Git failed with a fatal error.
具体错误信息:Git failed with a fatal error.error: open("ConsoleApp1/.vs/ConsoleApp1/v15/Server/sqlite ...
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 G. Xor
There is a tree with nn nodes. For each node, there is an integer value a_iai, (1 \le a_i \le 1,0 ...
- 清北学堂模拟赛d3t6 c
分析:比较神奇的一道题.要把树变成环肯定要先变成链,然后把链给拼接成环.接下来考虑一个脑洞大开的树形dp:设f[i][0]表示i不与父节点相连的链数,f[i][1]表示i与父节点相连的链数,先考虑怎么 ...