Kickstart Round G 2018
第一次打codejam....惨的一比,才A1.5题,感觉自己最近状态渣到姥姥家了,赶紧练练
A 模拟,注意0的问题
#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;
int n;
int A[N];
vector<int> vc[M];
int maxx;
int solve(ll x, int pos) {
if(x > maxx) return 0;
int tt = (lower_bound(vc[x].begin(), vc[x].end(), pos) - vc[x].begin());
return vc[x].size() - tt;
}
int main() {
freopen("A-large.in", "r", stdin);
freopen("A-large.out", "w", stdout);
// vector<int> t1;
// t1.push_back(1); t1.push_back(2);
// int tt = (lower_bound(t1.begin(), t1.end(), -1) - t1.begin());
// printf("%d\n", tt);
int T;
scanf("%d", &T);
for(int _ = 1; _ <= T; ++_){
for(int i = 0; i < M; ++i) vc[i].clear();
scanf("%d", &n);
maxx = -1;
for(int i = 1; i <= n; ++i) {
scanf("%d", &A[i]);
vc[A[i]].push_back(i);
maxx = max(maxx, A[i]);
}
ll ans = 0;
for(int i = 1; i <= n; ++i) {
for(int j = i + 1; j <= n; ++j) {
if(A[i] == 0 && A[j] == 0) ans += n - j;
else if(A[i] == 0 || A[j] == 0) ans += solve(0, j + 1);
else {
int pre = -1;
if(A[i] % A[j] == 0) ans += solve(A[i] / A[j], j+1), pre = A[i] / A[j];
if(A[j] % A[i] == 0 && pre != A[j] / A[i]) ans += solve(A[j] / A[i], j+1), pre = A[j] / A[i];
if(pre != 1ll * A[j] * A[i]) ans += solve(1ll * A[j] * A[i], j+1);
}
}
}
printf("Case #%d: %lld\n", _, ans);
}
return 0;
}
B 前缀和,二分
#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 = 4e5 + 5;
const int MM = 1e5 + 5;
// const int M = 2e5 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
typedef long long ll;
struct Node{
int num, offset;
Node(int a=0, int b=0):num(a), offset(b) {}
bool operator < (const Node &T) const {
if(num != T.num) return num < T.num;
else return offset < T.offset;
///
}
};
struct Tode{
ll sum; int val; int len; int now;
Tode(ll a=0, int b=0, int c=0, int d=0):sum(a), val(b), len(c), now(d){}
bool operator < (const Tode &T) const {
if(sum != T.sum) return sum < T.sum;
else return 1;
///
}
};
int n, q;
ll X[N], Y[N], A[5], B[5], C[5], M[5];
ll Z[MM];
Node seq[N * 2];
Tode prefix[N * 2];
ll hhh[N * 2];
int main() {
freopen("B-small-attempt4.in", "r", stdin);
freopen("B-small-attempt4.out", "w", stdout);
int T;
scanf("%d", &T);
for(int _ = 1; _ <= T; ++_){
scanf("%d %d", &n, &q);
scanf("%lld %lld %lld %lld %lld %lld", &X[1], &X[2], &A[1], &B[1], &C[1], &M[1]);
scanf("%lld %lld %lld %lld %lld %lld", &Y[1], &Y[2], &A[2], &B[2], &C[2], &M[2]);
scanf("%lld %lld %lld %lld %lld %lld", &Z[1], &Z[2], &A[3], &B[3], &C[3], &M[3]);
for(int i = 3; i <= n; ++i) {
X[i] = (A[1] * X[i - 1] + B[1] * X[i - 2] + C[1]) % M[1];
Y[i] = (A[2] * Y[i - 1] + B[2] * Y[i - 2] + C[2]) % M[2];
}
for(int i = 3; i <= q; ++i) {
Z[i] = (A[3] * Z[i - 1] + B[3] * Z[i - 2] + C[3]) % M[3];
}
for(int i = 1; i <= n; ++i) {
X[i] ++; Y[i] ++;
}
for(int i = 1; i <= q; ++i) Z[i] ++;
int tot = 0;
ll tt = 0;
for(int i = 1; i <= n; ++i) {
if(X[i] > Y[i]) swap(X[i], Y[i]);
// printf("%lld %lld\n", X[i], Y[i]);
tt += Y[i] - X[i] + 1;
seq[tot ++ ] = Node(X[i], 1);
seq[tot ++ ] = Node(Y[i] + 1, -1);
}
// printf("%lld\n", tt);
sort(seq, seq + tot);
// for(int i = 0; i < tot; ++i) printf("%d %d : ", seq[i].num, seq[i].offset); printf("\n");
// seq[tot] = Node(seq[tot - 1].num + 1, 0);
int tmp = 0;
int tot2 = 0;
ll all = 0;
for(int i = 1; i < tot; ++i) {
tmp += seq[i-1].offset;
if(seq[i].num != seq[i-1].num) {
int tt = seq[i].num - seq[i - 1].num;
prefix[tot2] = Tode(all, tmp, tt, seq[i-1].num);
// if(seq[i-1].num < 0) printf("hhh");
hhh[tot2 ++] = all;
// printf("%lld %d %d from %d to %d\n", all, tmp, tt, seq[i-1].num, seq[i].num);
all += 1ll * tt * tmp;
}
}
// printf("%lld\n", all);
ll ans = 0;
for(int i = 1; i <= q; ++i) {
// printf("hhh: %lld\n", Z[i]);
Z[i] = tt - Z[i] + 1;
if(Z[i] <= 0) continue;
// Z[i] = 1;
// printf("hhh: %lld\n", Z[i]);
int pos = lower_bound(hhh, hhh + tot2, Z[i]) - hhh;
pos --;
ll lef = Z[i] - prefix[pos].sum;
// printf("%d %d %lld\n", pos, prefix[pos].now, lef);
ll tt = prefix[pos].now + lef / prefix[pos].val ;
if(lef && (lef % prefix[pos].val == 0) ) tt --;
// printf("%lld\n", tt);
ans += 1ll * tt * i;
}
printf("Case #%d: %lld\n", _, ans);
}
return 0;
}
/*
3
5 5
3 1 4 1 5 9
2 7 1 8 2 9
4 8 15 16 23 42
3
5 1
3 1 4 1 5 9
2 7 1 8 2 9
4 8 15 16 23 42
5 5
3 1 4 1 5 9
2 7 1 8 2 9
4 8 15 16 23 42
1 2
0 0 0 0 0 1
0 0 0 0 0 1
0 1 0 0 0 2
100
1 2
0 0 0 0 0 1
0 0 0 0 0 1
0 1 0 0 0 2
100
55769 1
0 0 0 0 0 1000000000
999999999 999999999 0 0 999999999 1000000000
2512670 116262940 14464944 27962747 49835299 118572793
400000 1
97295458 97277314 13871606 251023440 11331260 274678035
97295458 97277314 13871606 251023440 11331260 274678035
244442 258459 136705 290087 276595 400000
*/
C 状压dp+dfs
#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 <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <assert.h>
#include <iomanip>
using namespace std;
const int N = 32768;
const int M = 2e5 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
typedef long long ll;
int n, m, e, sx, sy, tx, ty;
int mp[105][105];
int has[105][105];
int dir[][2] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };
ll energy[N];
int exiting[N];
int remain[N];
int tag[105][105];
vector<tuple<int, int, int> > trap;
int trapNum;
ll dp[N];
void solve(ll all, int id) {
memset(has, 0, sizeof(has));
queue<tuple<int, int> > Q;
Q.push(make_tuple(sx, sy));
has[sx][sy] = 1;
int flag = 0;
int remainNum = 0;
while(!Q.empty()) {
int x = get<0>(Q.front()); int y = get<1>(Q.front()); Q.pop();
if(x == tx && y == ty) {
flag = 1;
}
for(int i = 0; i < 4; ++i) {
int dx = x + dir[i][0]; int dy = y + dir[i][1];
if(dx < 1 || dx > n || dy < 1 || dy > m || has[dx][dy] || mp[dx][dy] == -100000) continue;
if(mp[dx][dy] < 0 ) {
remainNum |= 1 << tag[dx][dy]; continue;
}
all += mp[dx][dy];
has[dx][dy] = 1;
Q.push(make_tuple(dx, dy));
}
}
energy[id] = all;
exiting[id] = flag;
remain[id] = remainNum;
}
ll dfs(int mask) {
if(~dp[mask]) return dp[mask];
ll ans = -1;
if(exiting[mask] == 1) ans = energy[mask];
for(int i = 0; i < trapNum; ++i) {
if( (remain[mask] >> i) & 1) {
if(-mp[get<0>(trap[i])][get<1>(trap[i])] <= energy[mask])
ans = max(ans, dfs(mask | (1<<i)));
}
}
dp[mask] = ans;
return ans;
}
int main() {
freopen("./C-large-practice2.in", "r", stdin);
// freopen("./C-large-practice2.out", "w", stdout);
int T;
scanf("%d", &T);
for(int _ = 1; _ <= T; ++_){
trap.clear();
memset(dp, -1, sizeof(dp));
scanf("%d %d %d %d %d %d %d", &n, &m, &e, &sx, &sy, &tx, &ty);
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
scanf("%d", &mp[i][j]);
}
}
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
if(mp[i][j] < 0 && mp[i][j] != -100000) {
trap.emplace_back(i, j, mp[i][j]);
tag[i][j] = trap.size() - 1;
}
}
}
trapNum = trap.size();
for(int i = 0; i < 1 << trapNum; ++i) {
ll all = e;
for(int j = 0; j < trapNum; ++j) {
if( (i >> j) & 1 ) {
mp[get<0>(trap[j])][get<1>(trap[j])] = 0;
all += get<2>(trap[j]);
}
}
solve(all, i);
for(int j = 0; j < trapNum; ++j) {
if( (i >> j) & 1 ) {
mp[get<0>(trap[j])][get<1>(trap[j])] = get<2>(trap[j]);
}
}
}
// for(int i = 0; i < 1<<trapNum; ++i) printf("%lld %d %d\n", energy[i], remain[i], exiting[i]);
printf("Case #%d: %lld\n", _, dfs(0));
}
return 0;
}
/*
2
4 4 100 1 1 4 4
0 0 0 0
0 0 0 0
0 0 0 -100000
0 0 -100000 0
8 8 250 7 1 1 7
-100000 -100000 -100000 -100000 -100000 -100000 0 -100000
-100000 0 -100000 0 -400 0 0 -100000
-100000 100 -300 0 -100000 -300 -100000 -100000
-100000 0 -100000 500 -100000 250 0 -100000
-100000 -200 -100000 -100000 -100000 -100000 -100 -100000
-100000 0 -100000 0 0 50 50 -100000
0 0 -100 0 -100000 50 -100000 -100000
-100000 -100000 -100000 -100000 -100000 -100000 -100000 -100000
*/
Kickstart Round G 2018的更多相关文章
- google Kickstart Round G 2017 三道题题解
A题:给定A,N,P,计算A的N!次幂对P取模的结果. 数据范围: T次测试,1 ≤ T ≤ 100 1<=A,N,P<=105 快速幂一下就好了.O(nlogn). AC代码: #inc ...
- Kickstart Round H 2018
打了ks好久都没有更新 诶,自己的粗心真的是没救了,A题大数据都能错 A #include <iostream> #include <cstdio> #include < ...
- Let Me Count The Ways(Kickstart Round H 2018)
题目链接:https://code.google.com/codejam/contest/3324486/dashboard#s=p2 题目: 思路: 代码实现如下: #include <set ...
- Google Kickstart Round E 2018 B. Milk Tea
太蠢了,,,因为初始化大数据没过,丢了10分,纪念一下这个错误 大概思路:先求出让损失值最小的排列,由已生成的这些排列,通过更改某一个位置的值,生成下一个最优解,迭代最多生成m+1个最优解即可,遍历求 ...
- Google Kick Start Round G 2019
Google Kick Start Round G 2019 Book Reading 暴力,没啥好说的 #include<bits/stdc++.h> using namespace s ...
- 2019 google kickstart round A
第一题: n个人,每个人有一个对应的技能值s,现在要从n个人中选出p个人,使得他们的技能值相同. 显然,如果存在p个人的技能值是相同的,输出0就可以了.如果不存在,就要找出p个人,对他们进行训练,治他 ...
- 8VC Venture Cup 2016 - Elimination Round G. Raffles 线段树
G. Raffles 题目连接: http://www.codeforces.com/contest/626/problem/G Description Johnny is at a carnival ...
- Kickstart Round H 2019 Problem B. Diagonal Puzzle
有史以来打得最差的一次kickstart竟然发生在winter camp出结果前的最后一次ks = = 感觉自己的winter camp要凉了 究其原因,无非自己太眼高手低,好好做B, C的小数据,也 ...
- Kickstart Round D 2017 problem A sightseeing 一道DP
这是现场完整做出来的唯一一道题Orz..而且还调了很久的bug.还是太弱了. Problem When you travel, you like to spend time sightseeing i ...
随机推荐
- 数据结构&堆&heap&priority_queue&实现
目录 什么是堆? 大根堆 小根堆 堆的操作 STL queue 什么是堆? 堆是一种数据结构,可以用来实现优先队列 大根堆 大根堆,顾名思义就是根节点最大.我们先用小根堆的建堆过程学习堆的思想. 小根 ...
- echo,die(),print(),print_r(),var_dump()的区别
echo是PHP语句, print和print_r是函数,语句没有返回值,函数可以有返回值(即便没有用) print() 只能打印出简单类型变量的值(如int,string) 例子 输出 3 ...
- 【原创】Apache ab测试时出现:apr_socket_recv "connection reset by peer" 104
今天在用Apache自带的ab工具做以下简单的压测,本来是随便填几个参数,发现ab在1000并发以上报错:apr_socket_recv "connection reset by peer& ...
- 基于easyui开发Web版Activiti流程定制器详解(四)——页面结构(下)
题外话: 这两天周末在家陪老婆和儿子没上来更新请大家见谅!上一篇介绍了调色板和画布区的页面结构,这篇讲解一下属性区的结构也是定制器最重要的一个页面. 属性区整体页面结构如图: 在这个区域可以定义工作 ...
- Elasticsearch简单使用和环境搭建
Elasticsearch简单使用和环境搭建 1 Elasticsearch简介 Elasticsearch是一个可用于构建搜索应用的成品软件,它最早由Shay Bannon创建并于2010年2月发布 ...
- mongodb启动与运用
在操作前需要启动mongodb数据库服务 1.首先打开dos窗口,然后选择路径到你的安装路径下的bin目录(我的路径是的D:mongo\mongodb\bin) 2.然后输入启动命令(D:mongo\ ...
- @SpringBootApplication无法被解析引入
问题描述:@SpringBootApplication无法被解析引入,导致SpringBoot启动类报错 原因分析:springboot的包冲突了所致 解决方案: 需要删掉 repository\or ...
- python apsheduler cron 参数解析
from:https://apscheduler.readthedocs.io/en/v2.1.2/cronschedule.html Cron-style scheduling This is th ...
- (转)Python学习笔记系列——Python是一种纯粹的语言
此文出自知乎灵剑,原文传送门:https://zhuanlan.zhihu.com/p/23926957. 在摸索适合自己的语言学习方法,看到一篇好文章,转之,侵删. Python的语法范式相当多.知 ...
- P2983 [USACO10FEB]购买巧克力Chocolate Buying
题目描述 Bessie and the herd love chocolate so Farmer John is buying them some. The Bovine Chocolate Sto ...