第一次打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的更多相关文章

  1. 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 ...

  2. Kickstart Round H 2018

    打了ks好久都没有更新 诶,自己的粗心真的是没救了,A题大数据都能错 A #include <iostream> #include <cstdio> #include < ...

  3. Let Me Count The Ways(Kickstart Round H 2018)

    题目链接:https://code.google.com/codejam/contest/3324486/dashboard#s=p2 题目: 思路: 代码实现如下: #include <set ...

  4. Google Kickstart Round E 2018 B. Milk Tea

    太蠢了,,,因为初始化大数据没过,丢了10分,纪念一下这个错误 大概思路:先求出让损失值最小的排列,由已生成的这些排列,通过更改某一个位置的值,生成下一个最优解,迭代最多生成m+1个最优解即可,遍历求 ...

  5. Google Kick Start Round G 2019

    Google Kick Start Round G 2019 Book Reading 暴力,没啥好说的 #include<bits/stdc++.h> using namespace s ...

  6. 2019 google kickstart round A

    第一题: n个人,每个人有一个对应的技能值s,现在要从n个人中选出p个人,使得他们的技能值相同. 显然,如果存在p个人的技能值是相同的,输出0就可以了.如果不存在,就要找出p个人,对他们进行训练,治他 ...

  7. 8VC Venture Cup 2016 - Elimination Round G. Raffles 线段树

    G. Raffles 题目连接: http://www.codeforces.com/contest/626/problem/G Description Johnny is at a carnival ...

  8. Kickstart Round H 2019 Problem B. Diagonal Puzzle

    有史以来打得最差的一次kickstart竟然发生在winter camp出结果前的最后一次ks = = 感觉自己的winter camp要凉了 究其原因,无非自己太眼高手低,好好做B, C的小数据,也 ...

  9. Kickstart Round D 2017 problem A sightseeing 一道DP

    这是现场完整做出来的唯一一道题Orz..而且还调了很久的bug.还是太弱了. Problem When you travel, you like to spend time sightseeing i ...

随机推荐

  1. c++课程学习(未完待续)

    关于c++课程学习 按照计划,我首先阅读谭浩强c++程序设计一书的ppt,发现第一章基本上都是很基础的东西. 同时,书中与班导师一样,推荐了使用visual c++. 而师爷的教程里面推荐使用的是ec ...

  2. css-table属性运用

    最近在工作中遇到了一些不常用的布局,很多使用 CSS table 属性,并结合 ::before,::after 伪元素完成了,使得 HTML 的结构相对更简单,更具有语义性.当 HTML 结构越清晰 ...

  3. 2040-亲和数(java)

    http://acm.hdu.edu.cn/showproblem.php?pid=2040 import java.util.Scanner; public class Main{ public s ...

  4. Ubuntu中文目录文件夹改为英文

    打开终端,在终端中输入命令: export LANG=en_US xdg-user-dirs-gtk-update 在弹出的窗口中询问是否将目录转化为英文路径,同意并关闭. 在终端中输入命令: exp ...

  5. 看懂shebang吧,只需一点点shell知识,从此再也不犯强迫症

    Python2: 开启一个terminal,输入下面命令: yshuangj@ubuntu:~$ vim helloA.py 在vim编辑器中,进入编辑模式(按i),输入下面的代码,然后退出编辑模式( ...

  6. 20165318 2017-2018-2 《Java程序设计》第三周学习总结

    20165318 2017-2018-2 <Java程序设计>第三周学习总结 学习总结 我感觉从这一章开始,新的知识点扑面而来,很多定义都是之前没有接触过的,看书的时候难免有些晦涩.但由于 ...

  7. 1483. [HNOI2009]梦幻布丁【平衡树-splay】

    Description N个布丁摆成一行,进行M次操作.每次将某个颜色的布丁全部变成另一种颜色的,然后再询问当前一共有多少段颜色. 例如颜色分别为1,2,2,1的四个布丁一共有3段颜色. Input ...

  8. oracle 禁用/启动job

    注意:dbms_job只能在job的所在用户使用,如果broken其它用户的job用dbms_ijob dbms_job只能在当期用户内创建job.修改和删除job,不能对其他用户的job进行操作;s ...

  9. Day5 JDBC

    JDBC的简介 Java  Database Connectivity:连接数据库技术. SUN公司为了简化.统一对数据库的操作,定义了一套Java操作数据库的规范(接口),使用同一套程序操作不同的数 ...

  10. virtualbox+vagrant学习-4-Vagrantfile-6-SSH Settings

    SSH Settings 配置命名空间:config.ssh config.ssh的设置涉及到将如何配置vagrant使其通过ssh访问你的计算机.与大多数vagrant设置一样,默认设置通常都很好, ...