有史以来打得最差的一次kickstart竟然发生在winter camp出结果前的最后一次ks = = 感觉自己的winter camp要凉了

究其原因,无非自己太眼高手低,好好做B, C的小数据,也不至于最后才AC了第一题吧

B题,我花了两个小时也没AC = =,我的做法和题解大数据的第一种类似。

  1. 我们可以发现,每个点只由两个diagonal决定,然后每个diagonal至多做一次,做两次相当于白做嘛。

  2. 然后我们发现如果先讨论最长正对角线是否取,也就是从(0,0)到 (n-1,n-1),可以直接讨论出其中一半的diagonal和一半点的取舍问题,以5*5为例,如图所示。对于最长的正对角线上的每个元素,如果是'.', 那么必要动用他们所对应的反对角线才能翻过来,反之比不会动用这些反对角线。之后,如果这些被讨论到的反对角线上如果存在'.',那么我们就需要动用他们所对用的正对角线进行翻转。之后我们再判断是否所有点都被翻转了(图中最右边一张图重的所有黄色点)

  3. 上步我们发现我们只讨论一半的点和对角线的操作。对于 另一半,偶数长度边和奇数长度边的讨论是有些许不同的(如下图所示,奇数长度边的反最长对角线不在这一半中)。但是大方向一样,寻找剩下点中反对角线最长的一条,然后做和第二步类似的操作。要注意2,3两步都要先讨论对角线翻不翻转

细节还是看下代码 = = 写的有点长

#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <complex>
#include <cassert>
#include <random>
#include <cstring>
#include <numeric>
#define mp make_pair
#define ll long long
#define ld long double
#define null NULL
#define all(a) a.begin(), a.end()
#define forn(i, n) for (int i = 0; i < n; ++i)
#define sz(a) (int)a.size()
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define bitCount(a) __builtin_popcount(a)
template<class T> int gmax(T &a, T b) { if (b > a) { a = b; return 1; } return 0; }
template<class T> int gmin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; }
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif const int INF = 0x3f3f3f3f;
char seq[105][105];
int n;
int id1[105][105];
int id2[105][105];
int tmp[105][105]; vector<vector<pair<int, int> > > s1;
vector<vector<pair<int, int> > > s2;
void init() {
s1.clear(); s2.clear();
int cnt = 0;
for(int i = n-1; i >= 0; --i) {
int x = i; int y = 0;
vector<pair<int, int> > tmp;
while(1) {
id1[x][y] = cnt;
tmp.push_back(make_pair(x, y));
x ++; y ++;
if(x < 0 || x >= n || y < 0 || y >= n) break;
}
s1.push_back(tmp);
cnt ++;
} for(int i = 1; i <= n-1; ++i) {
int x = 0; int y = i;
vector<pair<int, int> > tmp;
while(1) {
id1[x][y] = cnt;
tmp.push_back(make_pair(x, y));
x ++; y ++;
if(x < 0 || x >= n || y < 0 || y >= n) break;
}
s1.push_back(tmp);
cnt ++;
} cnt = 0;
for(int i = 0; i <= n-1; ++i) {
int x = i; int y = 0;
vector<pair<int, int> > tmp;
while(1) {
id2[x][y] = cnt;
tmp.push_back(make_pair(x, y));
x --; y ++;
if(x < 0 || x >= n || y < 0 || y >= n) break;
}
s2.push_back(tmp);
cnt ++;
} for(int i = 1; i <= n-1; ++i) {
int x = n-1; int y = i;
vector<pair<int, int> > tmp;
while(1) {
id2[x][y] = cnt;
tmp.push_back(make_pair(x, y));
x --; y ++;
if(x < 0 || x >= n || y < 0 || y >= n) break;
}
s2.push_back(tmp);
cnt ++;
} // debug(s1, s2);
} int solve1(int ty) {
// debug(ty); int cnt = ty == 1; bool suc = true;
map<int, int> mp;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j) {
tmp[i][j] = seq[i][j] == '#';
}
}
vector<int> diagnol;
int target = s1.size() / 2;
for(int i = 0, len = s1[target].size(); i < len; ++i) {
int x = s1[target][i].first; int y = s1[target][i].second;
// debug(tmp[x][y], (ty == 1)); if(tmp[x][y] == (ty == 1) ) {
cnt ++;
diagnol.push_back(id2[x][y]); // debug("yingying"); } if(ty == 1) tmp[x][y] = !tmp[x][y];
} // debug(diagnol); for(int i = 0, len = diagnol.size(); i < len; ++i) {
for(int j = 0, len2 = s2[diagnol[i]].size(); j < len2; ++j) {
int x = s2[diagnol[i]][j].first; int y = s2[diagnol[i]][j].second;
// debug(x, y);
tmp[x][y] = !tmp[x][y];
}
} for(int i = target % 2; i < s1.size();i += 2) {
for(auto Point : s1[i]) {
int x = Point.first; int y = Point.second;
if(tmp[x][y] == 0) {
// debug(x, y);
mp[id1[x][y]] ++;
}
}
} for(auto it : mp) {
// debug(it.first, it.second);
cnt ++;
if(s1[it.first].size() != it.second) {
suc = false; break;
}
} if(suc == true) {
// debug(cnt);
return cnt;
}
else return INF;
} int solve2(int ty) {
int cnt = ty == 1; bool suc = true;
map<int, int> mp;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j) {
tmp[i][j] = seq[i][j] == '#';
}
}
vector<int> diagnol;
int target = s2.size() / 2;
if(n % 2) target --;
for(int i = 0, len = s2[target].size(); i < len; ++i) {
int x = s2[target][i].first; int y = s2[target][i].second; if(tmp[x][y] == (ty == 1) ) {
cnt ++;
diagnol.push_back(id1[x][y]); } if(ty == 1) tmp[x][y] = !tmp[x][y];
} // debug(diagnol); for(int i = 0, len = diagnol.size(); i < len; ++i) {
for(int j = 0, len2 = s1[diagnol[i]].size(); j < len2; ++j) {
int x = s1[diagnol[i]][j].first; int y = s1[diagnol[i]][j].second;
tmp[x][y] = !tmp[x][y];
}
} for(int i = 1; i < s2.size();i += 2) {
for(auto Point : s2[i]) {
int x = Point.first; int y = Point.second;
if(tmp[x][y] == 0) {
// debug(i, j)
mp[id2[x][y]] ++;
}
}
} for(auto it : mp) {
cnt ++;
if(s2[it.first].size() != it.second) {
suc = false; break;
}
} if(suc == true) return cnt;
else return INF;
} int main() {
int T;
scanf("%d", &T);
for(int cas = 1; cas <= T; ++cas) { scanf("%d", &n);
for(int i = 0; i < n; ++i) {
scanf("%s", seq[i]);
} init();
printf("Case #%d: ", cas); if(n == 1) {
printf("%d\n", seq[0][0] == '.');
continue;
}
printf("%d\n", min(solve1(1), solve1(0)) + min(solve2(1), solve2(0)) ); }
return 0;
}

Kickstart Round H 2019 Problem B. Diagonal Puzzle的更多相关文章

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

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

  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 Kick Start Round G 2019

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

  5. 清北学堂入学测试P4751 H’s problem(h)

    P4751 H’s problem(h)  时间: 1000ms / 空间: 655360KiB / Java类名: Main 背景 冬令营入学测试 描述 小H是一个喜欢逛街的女孩子,但是由于上了大学 ...

  6. 2019 google kickstart round A

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

  7. Kick Start 2019 Round H. Elevanagram

    设共有 $N = \sum_{i=1}^{9} A_i$ 个数字.先把 $N$ 个数字任意分成两组 $A$ 和 $B$,$A$ 中有 $N_A = \floor{N/2}$ 个数字,$B$ 中有 $N ...

  8. Codeforces Round #172 (Div. 2) C. Rectangle Puzzle 数学题几何

    C. Rectangle Puzzle Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/281/p ...

  9. 8VC Venture Cup 2016 - Final Round (Div. 2 Edition)B. sland Puzzle 水题

    B. sland Puzzle 题目连接: http://www.codeforces.com/contest/635/problem/B Description A remote island ch ...

随机推荐

  1. Vue中插槽指令

    08.29自我总结 Vue中插槽指令 意义 就是在组件里留着差值方便后续组件内容新增 而且由于插件是写在父级中数据可以直接父级中传输而不需要传子再传父有些情况会减少写代码量 示例 <div id ...

  2. 清理 Sketch缓存 Storyist 3.5.1中文破解版 for Mac

    Sketch这款软件可以用来做原型和UI设计,很多设计师和产品经理都在用,时间长了以后,Sketch会占据不少缓存空间,这时候可以试试 Sketch Cache Cleaner 这款软件清理历史文件和 ...

  3. 那些你不知道的HTML知识,快来学习一下吧

    前言 HTML作为前端三大基础知识点之一,是每一个前端开发人员都要掌握的部分.今天这篇文章我们来看看一些平时不太会注意,却在面试时可能会问到的题目,来看看你都会吗? 如何使用div模拟实现textar ...

  4. 维护基于ASP.NET的网站的学习-SqlCommand类介绍及存储过程

    笔者目前在维护学校科技处的一个网站,目前学期初,教师申报项目操作多,出现了一些问题.前几天维护了一个验证码图片不显示的bug,今天想记录下这个解决了一整天的bug-老师项目结题需要手动修改数据库老师项 ...

  5. [BZOJ2392][HAOI2011]Problem c

    Description 给n个人安排座位,先给每个人一个1~n的编号,设第i个人的编号为ai(不同人的编号可以相同),接着从第一个人开始,大家依次入座,第i个人来了以后尝试坐到ai,如果ai被占据了, ...

  6. Arduino学习笔记⑦ EEPROM断电保存数据

    1.前言     EEPROM,叫做电可擦可编程可读寄存器(是不是觉得好官方,不知道是什么鬼?反正我也一脸懵逼),只需要知道这是一种断电后数据不会丢失的存储设备,可以用来应对需要做记录做保存的场合.简 ...

  7. 图片放大缩小插件 zoom.js 怎么用

    代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf ...

  8. 破解Android设备无法联调的谜题

    这篇文章要感谢来自知乎的小伙伴:子非鱼,他最近被一件事情困惑,那就是:Android手机无法联调了.在解决完他的疑问后,突然意识到,其实自己在前一段时间也曾遇到同样的问题,最后居然还怀疑是电脑和手机不 ...

  9. Rancher 2.3.2 Stable!Istio UI已经GA!生产可用!

    2019年10月9日,Rancher 2.3正式发布,这是Rancher Labs迄今为止最重要的产品版本.Rancher 2.3是业界首个GA支持Windows容器的Kubernetes管理平台,并 ...

  10. NVDLA中Winograd卷积的设计

    在AI芯片:高性能卷积计算中的数据复用曾提到,基于变换域的卷积计算--譬如Winograd卷积--并不能适应算法上对卷积计算多变的需求.但Winograd卷积依旧出现在刚刚公开的ARM Ethos-N ...