本渣清明节 闲里偷忙 做了一下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. 如何在SAE搭建属于自己的黑盒xss安全测试平台

    Author:雪碧 http://weibo.com/520613815 此篇文章技术含量不高,大牛不喜勿喷,Thx!写这篇文章主要是为了各位小伙伴在SAE搭建XSSING平台的时候少走点弯路(同志们 ...

  2. MongoDB3.2配置文件.md

    Core Options systemLog Options systemLog: verbosity: <int> quiet: <boolean> traceAllExce ...

  3. 命令行翻译 推荐一个linux系统中可用的终端小程序

    程序的github地址:https://github.com/fanbrightup/fanyi 使用起来非常简单,同时支持中英文互译甚至是整句. 步骤一:首先你需要安装node,参见我的node安装 ...

  4. Nowcoder 提高组练习赛-R7

    Nowcoder 提高组练习赛-R7 https://www.nowcoder.com/acm/contest/179#question 中间空了两场,因为实在是太难了... 第五场的第二题好像还比较 ...

  5. Atcoder 水题选做

    为什么是水题选做呢?因为我只会水题啊 ( 为什么是$Atcoder$呢?因为暑假学长来讲课的时候讲了三件事:不要用洛谷,不要用dev-c++,不要用单步调试.$bzoj$太难了,$Topcoder$整 ...

  6. 【[AHOI2013]差异】

    这个题一看就是为后缀家族设计的 我们看到我们要求的这个柿子 \[\sum_{i=1}^n\sum_{j=i+1}^nT_i+T_j-2\times lcp(T_i,T_j)\] 显然的是前面的那些东西 ...

  7. Linq EF 添加数据执行事务处理

    在EF4.1的DBContext中实现事务处理(BeginTransaction)和直接执行SQL语句的示例 2012-12-12 10:39             5538人阅读          ...

  8. Kafka设计解析(二十二)Flink + Kafka 0.11端到端精确一次处理语义的实现

    转载自 huxihx,原文链接 [译]Flink + Kafka 0.11端到端精确一次处理语义的实现 本文是翻译作品,作者是Piotr Nowojski和Michael Winters.前者是该方案 ...

  9. Arduino入门笔记(8):利用12864和ADXL345学习重力感应控制

    转载请注明:@小五义 http://www.cnblogs.com/xiaowuyi 欢迎加入讨论群 64770604 一.本次实验所需器材 1.Arduino UNO板 https://item.t ...

  10. 使用Android绘图技术绘制一个椭圆形,然后通过触摸事件让该椭圆形跟着手指移动

    引言:在图形绘制中,控制一个图形(圆形,椭圆形,矩形,三角形)移动时,其实计算的都是该图形的中心点移动.在绘制过程中,首先计算出中心点,然后根据中心点的位置计算重图形的上下左右位置.我们假设图形左边为 ...