D.What a Mess

给n个数,求其中能满足 a[i] % a[j] == 0 的数对之和

n = 1W,max_ai = 100W 不是很大,所以就直接筛就可以了

计算可得最高复杂度 < 1kW

...考场上写了这个解法,结果把 j += i 写成了 j ++ ...

我还以为是单个测试点case太多...多么痛的领悟...

 #include <bits/stdc++.h>

 using namespace std;

 int Case, n, m, k, a[], b[];

 int main() {
scanf("%d", &Case);
while(Case --) {
m = , k = ;
scanf("%d", &n);
for(int i = ;i <= n;i ++) scanf("%d", &a[i]), b[a[i]] ++, k = max(k, a[i]);
for(int i = ;i <= k;i ++) {
if(!b[i]) continue;
m += b[i] * (b[i] - ) / ;
for(int j = i << ;j <= k;j += i)
m += b[j] * b[i];
}
printf("%d\n", m);
for(int i = ;i <= n;i ++) b[a[i]] --;
}
return ;
}

H.Paint it really, really dark gray

之前写过...但因为清楚记得之前调了一段时间...最后时间不是很多就去看D了...迷

假如递归过程中,当前节点的子节点都是叶子节点,那么只要访问一下需要染色的节点再回来就可以了

这样它的子节点都满足要求了,那么当前节点就可以看作是叶子节点了,然后处理上一层...

 #include <bits/stdc++.h>

 using namespace std;

 int n, a[], v[];

 vector <int> e[], ans;

 bool d[];

 void dfs(int x) {
a[x] = d[x] = (a[x] == -), v[x] = ;
for(int i = ;i < e[x].size();i ++) {
if(v[e[x][i]]) continue;
dfs(e[x][i]);
d[x] |= d[e[x][i]];
}
} void dfs_(int x, int f) {
a[x] ^= , ans.push_back(x);
for(int i = ;i < e[x].size();i ++) {
if(e[x][i] == f) continue;
if(d[e[x][i]]) dfs_(e[x][i], x), ans.push_back(x), a[x] ^= ;
}
if(a[x] && x != ) ans.push_back(f), ans.push_back(x), a[f] ^= , a[x] ^= ;
} int main() {
ios::sync_with_stdio(false);
cin >> n;
for(int i = ;i <= n;i ++) cin >> a[i];
int u, v;
for(int i = ;i < n;i ++) {
cin >> u >> v;
e[u].push_back(v);
e[v].push_back(u);
}
dfs(), dfs_(, );
for(auto it : ans) printf("%d ", it);
if(!a[]) printf("%d 1 %d", e[][], e[][]);
return ;
}

A.Treasure Island

数据范围其实不大,对于不止一种解的解决办法

就暴力测试每一个 '?' 就可以了

 #include <bits/stdc++.h>

 #define rep(i, j, k) for(int i = j;i <= k;i ++)

 int n, m, sx, sy, cnt, lcnt, last;

 char s[][];

 int mmp[][];

 const int xx[] = {, , , -};
const int yy[] = {, -, , }; void dfs(int x, int y, int nx = , int ny = ) {
cnt ++;
rep(i, , ) {
nx = x + xx[i], ny = y + yy[i];
if(nx > && nx <= n && ny > && ny <= m && s[nx][ny] != '#' && !mmp[nx][ny]) {
mmp[nx][ny] = ;
if(s[nx][ny] == '?') s[nx][ny] = '!';
dfs(nx, ny);
}
}
} int main() {
scanf("%d %d", &n, &m);
rep(i, , n) scanf("%s", s[i] + );
rep(i, , n) rep(j, , m)
if(s[i][j] == '.' && !mmp[i][j]) {
lcnt ++, sx = i, sy = j;
if(lcnt == ) {
puts("Impossible");
return ;
}
mmp[i][j] = , dfs(i, j);
}
last = cnt;
rep(i, , n) rep(j, , m) {
if(s[i][j] == '?') s[i][j] = '#';
else if(s[i][j] == '!') {
s[i][j] = '#', cnt = ;
memset(mmp, , sizeof mmp);
mmp[sx][sy] = , dfs(sx, sy);
if(cnt + == last) {
puts("Ambiguous");
return ;
}
else s[i][j] = '.';
}
}
rep(i, , n) puts(s[i] + );
return ;
}

bupt summer training for 16 #1 ——简单题目的更多相关文章

  1. bupt summer training for 16 #8 ——字符串处理

    https://vjudge.net/contest/175596#overview A.设第i次出现的位置左右端点分别为Li,Ri 初始化L0 = 0,则有ans = sum{ (L[i] - L[ ...

  2. bupt summer training for 16 #6 ——图论

    https://vjudge.net/contest/174020 A.100条双向边,每个点最少连2个边 所以最多100个点,点的标号需要离散化 然后要求恰好经过n条路径 快速幂,乘法过程就是flo ...

  3. bupt summer training for 16 #4 ——数论

    https://vjudge.net/contest/173277#overview A.平方差公式后变为 n = (x + y)(x - y) 令 t = x - y ,变成 n = (t + 2x ...

  4. bupt summer training for 16 #2 ——计算几何

    https://vjudge.net/contest/171368#overview A.一个签到题,用叉积来判断一个点在一条线的哪个方向 可以二分,数据范围允许暴力 #include <cst ...

  5. bupt summer training for 16 #7 ——搜索与DP

    https://vjudge.net/contest/174962#overview A.我们发现重点在于x,y只要累加就ok了 在每个x上只有上下两种状态,所以可以记忆化搜索 f[0/1][i]表示 ...

  6. bupt summer training for 16 #5 ——数据结构

    https://vjudge.net/contest/173780 A.假设 Pt = i,则由Ppi = i得 Ppt = t = Pi 所以就有 if Pt = i then Pi = t #in ...

  7. bupt summer training for 16 #3 ——构造

    https://vjudge.net/contest/172464 后来补题发现这场做的可真他妈傻逼 A.签到傻逼题,自己分情况 #include <cstdio> #include &l ...

  8. BUPT2017 springtraining(16) #1 ——近期codeforces简单题目回顾

    这里是contest 8道题全部来源于 cf 的两场contest (出题人可真懒啊 Codeforces Round #411 (Div. 2)的ABCDE Codeforces Round #40 ...

  9. 【Android Developers Training】 16. 暂停和恢复一个Activity

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...

随机推荐

  1. 【HDU1530】【ZOJ1492】Maximum Clique

    Position: http://poj.org/problem?id=3241 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCod ...

  2. imagebutton 设置了src属性的图片更换

    <ImageButton android:id="@+id/mediacontroller_play_pause" android:layout_width="wr ...

  3. PCB SQL SERVER 枚举分割函数(枚举值分解函数)

    在SQL SERVER字段采用枚举值作为字段后,如果直接查看字段的值是很难判断这个字段的带表什么意思, 在这里介绍如用函数的方法实现枚举值分割,只有分割后才很方便知道枚举值的意思. 一.问题说明 1. ...

  4. [Swift通天遁地]七、数据与安全-(2)对XML和HTML文档的快速解析

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  5. 2019 年了,为什么我还在用 jQuery?

    译者按: 看来 jQuery 还是有一些用武之地的. 原文: Why I'm Still Using jQuery in 2019 译者: Fundebug 为了保证可读性,本文采用意译而非直译.翻译 ...

  6. BZOJ 4310 二分+SA+RMQ

    思路: 首先求出后缀数组和height数组,这样能得到本质不同的子串数目 这里利用:本质不同的子串=∑(Len−SA[i]−height[i])=∑(Len−SA[i]−height[i])利用SA[ ...

  7. 解决:efi usb device has been blocked by the current security policy

    解决:efi usb device has been blocked by the current security policy 问题描述:U盘装系统或者其他操作时,是因为BIOS安全策略,出现上述 ...

  8. python自动化测试框架(一)

    1.开发环境 名称 版本 系统 windows 7 python版本 2.7.14 IDE pycharm2017 2.大致框架流程 :展示了框架实现的业务流程 3.框架介绍 3.1 ======完善 ...

  9. 在VirtualBox上安装Solaris 10全教程(包括下载)

    您可以在博文的最下方留下评价, 也可以点击左边的 关注 来关注我的博客的最新动态. 如果文章内容对您有帮助, 不要忘记点击右下角的 推荐 来支持一下喔 如果您对博文有任何疑问, 可以通过评论或发邮件的 ...

  10. JS——scroll

    scrollWidth:父div宽度小于子div宽度,父div scrollWidth宽度为子div的宽度,大于则为本身的宽度width+padding scrollHeight:父div高度小于子d ...