本渣清明节 闲里偷忙 做了一下codejam

水平不出意外的在投稿之后一落千丈

后两题的hidden test竟然都挂了

A. Foregone Solution

水题,稍微判断一下特殊情况(比如1000, 5000这种)就好了

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <functional>
// #include <assert.h>
#include <iomanip>
using namespace std;
const int N = 7005;
const int M = 2e5 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
typedef long long ll; char num[105];
char a[105];
char b[105];
int main() {
int _;
scanf("%d", &_);
for(int cas = 1; cas <= _; ++cas) {
scanf("%s", num); bool flag = true;
for(int i = 0, len = strlen(num); i < len; ++i) {
if(num[i] == '4') {
a[i] = '2';
b[i] = '2';
flag = false;
} else {
a[i] = num[i];
b[i] = '0';
}
} if(flag == true) {
int pos = -1; for(int i = strlen(num) - 1; i >= 0; --i) {
if(num[i] != '0') {
pos = i;
// if(num[i] == '1') {
// hasOne = true;
// }
break;
}
}
int hasOne = false;
for(int i = 0, len = strlen(num); i < len; ++i) {
if(i < pos) {
a[i] = num[i];
b[i] = '0';
} else if(i == pos) {
if(num[i] == '5') {
a[i] = '3';
b[i] = '2';
} else if(num[i] == '1' && i != strlen(num) - 1) {
a[i] = '0';
b[i] = '0';
hasOne = true;
} else {
a[i] = num[i] - 1;
b[i] = '1';
}
} else {
if(hasOne) {
a[i] = '9';
b[i] = (i == strlen(num) - 1) ? '1' :'0';
} else {
a[i] = num[i];
b[i] = '0';
}
}
}
} printf("Case #%d: ", cas);
for(int i = 0, len = strlen(num), flag = true; i < len; ++i) {
if(a[i] == '0' && flag) {
} else {
flag = false;
printf("%c", a[i]);
}
}
printf(" ");
for(int i = 0, len = strlen(num), flag = true; i < len; ++i) {
if(b[i] == '0' && flag) {
} else {
flag = false;
printf("%c", b[i]);
}
}
printf("\n"); }
return 0;
}

B. You Can Go Your Own Way

水题,直接和她反着来就好了

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <functional>
// #include <assert.h>
#include <iomanip>
using namespace std;
const int N = 7005;
const int M = 2e5 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
typedef long long ll; char seq[100005];
char result[100005];
int main() {
int _;
scanf("%d", &_);
for(int cas = 1; cas <= _; ++cas) {
int n;
scanf("%d %s", &n, seq);
for(int i = 0, len = strlen(seq); i < len; ++i) {
if(seq[i] == 'S')
result[i] = 'E';
else
result[i] = 'S';
} printf("Case #%d: ", cas);
for(int i = 0, len = strlen(seq); i < len; ++i) {
printf("%c", result[i]);
}
printf("\n"); }
return 0;
}

C. Cryptopangrams

大家都知道求下相邻的数的gcd,然后去重,排序

有个小坑就是,序列当中可能相邻的数是相同的,也就意味着有原始密码有a,b,a这种。需要找到一个相邻的数不相同的,然后反推其他的所有

其次就是大数,c++模版不好找,不如写java, python

import java.io.*;
import java.util.*;
import java.math.*; public class Solution {
Scanner in = new Scanner(new BufferedInputStream(System.in));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
BigInteger seq[] = new BigInteger[105];
BigInteger prime[] = new BigInteger[105];
// BigInteger num[] = new BigInteger[105];
int lower_bound(BigInteger[] nums, int begin, int end, BigInteger value) {
while (begin < end) {
int mid = begin + (end - begin) / 2;
if (nums[mid].compareTo(value) == -1) {
begin = mid + 1;
} else {
end = mid;
}
}
return begin;
}
void solve() {
int casNum;
casNum = in.nextInt();
for(int cas = 1; cas <= casNum; ++cas) {
BigInteger n;
int l;
n = in.nextBigInteger(); l = in.nextInt();
for(int i = 0; i < l; ++i) {
seq[i] = in.nextBigInteger();
} int pos = -1;
for(int i = 1; i < l; ++i) {
if(seq[i].equals(seq[i-1]) == false) {
prime[i] = seq[i].gcd(seq[i-1]);
pos = i;
break;
}
} for(int i = pos - 1; i >= 0; --i) {
prime[i] = seq[i].divide(prime[i + 1]);
}
for(int i = pos + 1; i <= l; ++i) {
prime[i] = seq[i-1].divide(prime[i-1]);
} List<BigInteger> num=new ArrayList<>();
for(int i = 0; i <= l; ++i) {
num.add(prime[i]);
}
Set<BigInteger> uniqueGas = new HashSet<BigInteger>(num);
// out.println(uniqueGas.size());
// for(BigInteger i : uniqueGas) {
// out.println(i);
// }
BigInteger[] result = uniqueGas.toArray(new BigInteger[0]);
Arrays.sort(result, 0, uniqueGas.size());
assert(uniqueGas.size() == 26);
// printf("%d\n", (int)num.size());
// for(int i = 0, len = num.size(); i < len; ++i) printf("%lld ", num[i]); printf("\n");
out.printf("Case #%d: ", cas); for(int i = 0; i <= l; ++i) {
int tt = lower_bound(result,0, uniqueGas.size(), prime[i]);
out.printf("%c", tt + 'A');
}
out.printf("\n");
}
out.flush();
}
public static void main(String args[]) {
new Solution ().solve(); }
}

D. Dat Bae

如果B没有小于等于15的限制的话,本渣觉得需要10次查询,这也是本渣的解法

不断二分01查询,比如0011, 0101这样查,就能最后判断出来每个位置在不在

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <functional>
#include <assert.h>
#include <iomanip>
using namespace std;
const int N = 7005;
const int M = 2e5 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
typedef long long ll; vector<pair<int, int> > prepare;
vector<pair<int, int> > solve;
vector<int> preClip;
vector<int> solveClip;
int result[2005];
char answer[2005];
int main() {
int _;
scanf("%d", &_);
for(int cas = 1; cas <= _; ++cas) {
int n, b, f;
scanf("%d %d %d", &n, &b, &f);
prepare.clear();
preClip.clear();
prepare.push_back(make_pair(1, n));
preClip.push_back(n - b); while(1) {
solveClip.clear();
solve.clear();
int flag = false;
int maxx = -1;
for(int i = 0, len = prepare.size(); i < len; ++i) {
int start = prepare[i].first; int end = prepare[i].second;
// if(end == start) {
// solve.push_back(make_pair(start, end));
// } else {
int mid = (start + end) / 2;
solve.push_back(make_pair(start, mid));
solve.push_back(make_pair(mid + 1, end));
// }
maxx = max(maxx, end - start);
}
if(maxx == 1) flag = true; for(int i = 0, len = solve.size(); i < len; ++i) {
int start = solve[i].first; int end = solve[i].second;
for(int j = start; j <= end; ++j) {
printf("%d", (i % 2 == 0) ? 0 : 1);
}
}
printf("\n");
fflush(stdout);
scanf("%s", answer);
for(int i = 0, len = preClip.size(), pre = 0; i < len; ++i) {
int pos = pre + preClip[i];
for(int j = pre, endJ = pre + preClip[i]; j < endJ; ++j) {
if(answer[j] == '1') {
pos = j;
break;
}
}
solveClip.push_back(pos - pre);
solveClip.push_back(preClip[i] - pos + pre);
pre += preClip[i];
} if(flag == true) break; // assert(solve.size() == solveClip.size());
// for(int i = 0, len = solve.size(); i < len; ++i) {
// int start = solve[i].first; int end = solve[i].second; int val = solveClip[i];
// printf("%d %d %d: ", start, end, val);
// } printf("\n"); prepare.swap(solve);
preClip.swap(solveClip);
} assert(solve.size() == solveClip.size()); for(int i = 0, len = solve.size(); i < len; ++i) {
int start = solve[i].first; int end = solve[i].second; int val = solveClip[i];
if(start == end) {
if(val == 1) {
result[start] = 1;
} else {
result[start] = 0;
}
}
}
for(int i = 1, fir = true; i <= n; ++i) {
if(result[i] == 0) {
if(fir) fir = false;
else printf(" ");
printf("%d", i - 1);
}
}
printf("\n");
fflush(stdout); int basa;
scanf("%d", &basa);
}
return 0;
} /*
1000
5 2 10
answer(0 3)
2 1 10
answer(0) */

但是如果只是5次查询,这样不行。反过来通过1,2,4,8为界的查询方式,判断一个16个数的组的borken情况。

如下所示

0101010101010101

0011001100110011

0000111100001111

0000000011111111

可以每16个数一个组,因为我们知道最多15个broken,每组必会有数保留,那么我们就可以判断出每个数是在哪个组当中的。贴下别人的代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <functional>
#include <assert.h>
#include <iomanip>
using namespace std;
const int N = 7005;
const int M = 2e5 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
typedef long long ll; void solve(){
int F = 4;
int n, b, fake_f;
cin >> n >> b >> fake_f;
// assert(fake_f >= F);
for(int f = 0; f < F; f++){
string g;
for(int i = 0; i < n; i++){
g += (char)('0' + ((i >> f) & 1));
}
cout << g << '\n' << flush;
}
vector<int> answers(n-b);
for(int f = 0; f < F; f++){
string res;
cin >> res;
for(int i = 0; i < n-b; i++){
answers[i] ^= (res[i] - '0') << f;
}
// for(int i = 0; i < n - b; ++i) {
// printf("%d ", answers[i]);
// } printf("\n");
}
vector<int> broken;
int z = 0;
for(int i = 0; i < n-b; i++){
while((z & 15) != answers[i]){
cout << z << ' ';
z++;
}
z++;
}
while(z < n){
cout << z << ' ';
z++;
}
cout << '\n';
cout << flush;
int res;
cin >> res;
} int main(){
int T;
cin >> T;
for(int t = 1; t <= T; t++){
solve();
}
} /*
1000
5 2 10 01010
00110
00001
00000
00000
100
010
001
000
000
answer(0 3)
000
010
001
000
000
answer(0 3) 2 1 10
answer(0) */

Codejam Qualification Round 2019的更多相关文章

  1. Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words

    Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words https://code.google.com/cod ...

  2. Google Code Jam Africa 2010 Qualification Round Problem A. Store Credit

    Google Code Jam Qualification Round Africa 2010 Problem A. Store Credit https://code.google.com/code ...

  3. Facebook Hacker Cup 2014 Qualification Round 竞赛试题 Square Detector 解题报告

    Facebook Hacker Cup 2014 Qualification Round比赛Square Detector题的解题报告.单击这里打开题目链接(国内访问需要那个,你懂的). 原题如下: ...

  4. DP VK Cup 2012 Qualification Round D. Palindrome pairs

    题目地址:http://blog.csdn.net/shiyuankongbu/article/details/10004443 /* 题意:在i前面找回文子串,在i后面找回文子串相互配对,问有几对 ...

  5. Facebook Hacker Cup 2014 Qualification Round

    2014 Qualification Round Solutions 2013年11月25日下午 1:34 ...最简单的一题又有bug...自以为是真是很厉害! 1. Square Detector ...

  6. [C++]Store Credit——Google Code Jam Qualification Round Africa 2010

    Google Code Jam Qualification Round Africa 2010 的第一题,很简单. Problem You receive a credit C at a local ...

  7. dp - Google Code jam Qualification Round 2015 --- Problem B. Infinite House of Pancakes

    Problem B. Infinite House of Pancakes Problem's Link:   https://code.google.com/codejam/contest/6224 ...

  8. Google Code jam Qualification Round 2015 --- Problem A. Standing Ovation

    Problem A. Standing Ovation Problem's Link:   https://code.google.com/codejam/contest/6224486/dashbo ...

  9. Google Code Jam 2009 Qualification Round Problem C. Welcome to Code Jam

    本题的 Large dataset 本人尚未解决. https://code.google.com/codejam/contest/90101/dashboard#s=p2 Problem So yo ...

随机推荐

  1. Software Engineer’s path to the best annual performance review

    http://michaelscodingspot.com/2017/06/04/software-engineers-path-best-annual-performance-review/ How ...

  2. VS2008 开发wince程序设备调试

    今天之前开发的一个wince程序,用户反馈报错,由于很久没玩了,从用户那里拿来设备.结果怎么调试的忘记了.在网上找了些资料,自己有摸索了一下.才搞定. 1.安装Microsoft ActiveSync ...

  3. 用JS制作《飞机大作战》游戏_第2讲(四大界面之间的跳转与玩家飞机的移动)-陈远波

    一.通过点击按钮事件,实现四大界面之间的跳转: (一)跳转的思路: 1.打开软件,只显示登录界面(隐藏游戏界面.暂停界面.玩家死亡界面) 2.点击微信登录(QQ登录)跳转到游戏界面,隐藏登录界面 3. ...

  4. oc 的 协变性与逆变性

    ?协变性与逆变性是类型关系在范畴论的定义.是类型的继承关系在高阶类型中的定义? __kindof只是在统一继承体系下方便了类型转化,提供了使用时语法上的便捷:但是对于类型转换是否正确不做判定: kin ...

  5. Netty入门(二)时间服务器及客户端

    在这个例子中,我在服务器和客户端连接被创立时发送一个消息,然后在客户端解析收到的消息并输出.并且,在这个项目中我使用 POJO 代替 ByteBuf 来作为传输对象. 一.服务器实现 1.  首先我们 ...

  6. luogu P3690 【模板】Link Cut Tree (动态树)

    嘟嘟嘟 LCT竟然看了整整一天,但好歹是看懂了. 教程这里不写,强烈推荐 闪狐大佬的博客 . 但是还是有几句想说的. 1.尽管LCT和splay很像,但是有一些细节还是不一样的.首先是rotate,我 ...

  7. docker 1.13.1 启动容器过程中mount报错

    docker 1.13.1 启动container 问题 [root@openfalcon_transfer1 harbor]# docker run -it --name test busybox ...

  8. SpringMVC之ajax+select下拉框交互常用方式

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. 本地模拟服务器CDN(静态HTML,CSS,JS)开发

    本地模拟服务器CDN(静态HTML,CSS,JS)开发 所谓本地开发环境就是和线上cdn(a.longencdn.cn)一样的目录结构和功能,提供了一个本地镜像,开发者直接在本地镜像的对应目录中作开发 ...

  10. css实现气泡框效果

    前提:气泡框或者提示框是网页很常见的,实现它的方式有很多,我们以前最常用的就是切图片 然后通过 "定位" 方式 定位到相应的位置,但是用这种方式维护很麻烦,比如设计师想改成另外一种 ...