Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)
以后每做完一场CF,解题报告都写在一起吧
暴力||二分 A - Bear and Elections
题意:有n个候选人,第一个候选人可以贿赂其他人拿到他们的票,问最少要贿赂多少张票第一个人才能赢
分析:正解竟然是暴力!没敢写暴力,卡了很久,导致这场比赛差点爆零!二分的话可以优化,但对于这题来说好像不需要。。。
收获:以后CF div2的A题果断暴力
代码(暴力):
/************************************************
* Author :Running_Time
* Created Time :2015-8-30 0:40:46
* File Name :A.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e3 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int a[N];
int n, x; int main(void) {
scanf ("%d", &n);
scanf ("%d", &a[0]); n--;
for (int i=1; i<=n; ++i) scanf ("%d", &a[i]);
int ans = 0;
while (true) {
int mxi = 0;
for (int i=1; i<=n; ++i) {
if (a[i] >= a[mxi]) mxi = i;
}
if (mxi == 0) break;
ans++; a[0]++; a[mxi]--;
}
printf ("%d\n", ans); return 0;
}
代码(二分):
/************************************************
* Author :Running_Time
* Created Time :2015-8-30 0:40:46
* File Name :A.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e3 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int a[N];
int n; bool cmp(int x, int y) {
return x > y;
} bool check(int add) {
int y = a[0] + add;
for (int i=1; i<=n; ++i) {
if (a[i] >= y) {
if (add <= 0) return false;
add -= (a[i] - (y - 1));
if (add < 0) return false;
}
else break;
}
return true;
} int main(void) {
scanf ("%d", &n);
scanf ("%d", &a[0]); n--;
for (int i=1; i<=n; ++i) scanf ("%d", &a[i]);
sort (a+1, a+1+n, cmp);
if (a[0] > a[1]) {
puts ("0"); return 0;
}
int l = 0, r = 1000;
while (l <= r) {
int mid = (l + r) >> 1;
if (check (mid)) r = mid - 1;
else l = mid + 1;
}
printf ("%d\n", l); return 0;
}
暴力 B - Bear and Three Musketeers
题意:找一个三元环并且三个点的度数和-6最小
分析:三元环做过一题。这题能暴力跑过,DFS不用写。枚举边的两个端点,再找是否存在另外一个点构成三元环就可以了
收获:CF div2 B也暴力过
代码:
/************************************************
* Author :Running_Time
* Created Time :2015-8-25 19:24:24
* File Name :E_topo.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
typedef pair<int, int> PII;
const int N = 4e3 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int deg[N];
bool g[N][N];
vector<PII> G;
int n, m; int main(void) {
scanf ("%d%d", &n, &m);
G.clear ();
memset (g, false, sizeof (g));
memset (deg, 0, sizeof (deg)); for (int u, v, i=1; i<=m; ++i) {
scanf ("%d%d", &u, &v);
G.push_back (PII (u, v));
g[u][v] = true; g[v][u] = true;
deg[u]++; deg[v]++;
} int ans = INF;
for (int i=0; i<G.size (); ++i) {
int u = G[i].first, v = G[i].second;
for (int j=1; j<=n; ++j) {
if (g[u][j] && g[v][j]) {
ans = min (ans, deg[u] + deg[v] + deg[j] - 6);
}
}
} printf ("%d\n", (ans == INF) ? -1 : ans); return 0;
}
题意:给n个数字,每个数字能*2或*3(可多次),问是否能使得n个数相等
分析:要达到相等,那么每个数字除了2和3的数字外的剩余数字要相等,一个数除2或3是log级别的? 复杂度不会分析。。。
收获:其实这题很水,想到/2 /3就行了
代码:
/************************************************
* Author :Running_Time
* Created Time :2015-8-30 1:42:08
* File Name :C.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int a[N]; int GCD(int a, int b) {
return b ? GCD (b, a % b) : a;
} int main(void) {
int n; scanf ("%d", &n);
for (int i=1; i<=n; ++i) scanf ("%d", &a[i]);
bool flag = true;
for (int i=1; i<=n; ++i) {
while (a[i] % 2 == 0) a[i] /= 2;
while (a[i] % 3 == 0) a[i] /= 3;
}
for (int i=1; i<n; ++i) {
if (a[i] != a[i+1]) {
flag = false; break;
}
}
puts (flag ? "Yes" : "No"); return 0;
}
题意:有n列高度不等的方块,每次可以将和空气(至少一面不和砖头或地面接触)接触的搬走,问要搬几次
分析:先考虑一列方块时只要搬一次。两列时,如果第二列高度大于第一列,那么搬两次,否则只搬一次。三列的情况同理
问题转换成最长连续上升序列,从前往后扫一次还有从后往前扫一次,两次取最小值,答案取最大值
代码:
/************************************************
* Author :Running_Time
* Created Time :2015-8-30 16:56:38
* File Name :D.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int a[N], dp1[N], dp2[N]; int main(void) {
int n; scanf ("%d", &n);
for (int i=0; i<n; ++i) scanf ("%d", &a[i]);
dp1[0] = 1;
for (int i=1; i<n; ++i) dp1[i] = min (a[i], dp1[i-1] + 1);
dp2[n-1] = 1;
for (int i=n-2; i>=0; --i) dp2[i] = min (a[i], dp2[i+1] + 1);
int ans = 0;
for (int i=0; i<n; ++i) {
ans = max (ans, min (dp1[i], dp2[i]));
}
printf ("%d\n", ans); return 0;
}
Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)的更多相关文章
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) B. Bear and Blocks 水题
B. Bear and Blocks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/573/pr ...
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) A. Bear and Poker 分解
A. Bear and Poker Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/573/pro ...
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) C. Bear and Drawing
题目链接:http://codeforces.com/contest/573/problem/C题目大意:在两行无限长的点列上面画n个点以及n-1条边使得构成一棵树,并且要求边都在同一平面上且除了节点 ...
- 校内选拔I题题解 构造题 Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) ——D
http://codeforces.com/contest/574/problem/D Bear and Blocks time limit per test 1 second memory limi ...
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) A. Bear and Elections 优先队列
A. Bear and Elections ...
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) B. Bear and Three Musketeers 枚举
B. Bear and Three Musketeers ...
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)C. Bear and Poker
C. Bear and Poker ...
- Codeforces Round #539Ȟȟȡ (Div. 1) 简要题解
Codeforces Round #539 (Div. 1) A. Sasha and a Bit of Relax description 给一个序列\(a_i\),求有多少长度为偶数的区间\([l ...
- Codeforces Round VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM 暴力出奇迹!
VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM Time Lim ...
随机推荐
- Meteor跟踪器(Tracker)
跟踪器是用于当模板会话变量发生了变化自动更新的一个小型库. 为了向你展示跟踪器是如何工作的,我们将创建按钮将用于更新会话. meteorApp/import/ui/meteorApp.html < ...
- IntelliJ IDEA14.0.3+Maven+SpringMVC+Spring+Hibernate光速构建Java权限管理系统(三)
注册登录 --利用简单的编写注册登录系统来打通从前端到后台的数据传输路径. 一.建立数据库.基本表 基本环境:mysql5,7.Navicat for MySQL11.0.9企业版. 我们在本地MyS ...
- uva 10069 Distinct Subsequences 【dp+大数】
题目:uva 10069 Distinct Subsequences 题意:给出一个子串 x 和母串 s .求子串在母串中的不同序列的个数? 分析:定义dp[i][j]:x 的前 i 个字母在 s 的 ...
- Office2010,PPT,EXCEL如何插入日历控件
1 在Office2010中插入其他控件,然后找到日历控件 2 十字架随便在Excel中绘制一下,得到一个日历控件,注意此时还是在设计模式下,在设计模式下日历控件不是正常状态,你还是可以双击这个控 ...
- freemarker 模板
1 整体结构 模板(FTL 编程)是由例如以下部分混合而成的: Text 文本:文本会照着原样来输出. Interpolation 插值:这部分的输出会被计算的值来替换.插值由${和}所分隔(或者#{ ...
- Linux环境搭建:1. 安装VMware
我家淘宝店,主要协助同学做毕业设计:https://shop104550034.taobao.com/?spm=2013.1.1000126.d21.pPCzDZ 1. 下载VMware 能够到我的3 ...
- Eclipse:Some sites could not be found. See the error log for more detail.解决的方法
今天遇到了一个奇葩的问题.我把我的sdk tools的版本号升级到23后.我在eclipse中尝试升级ADT,发现了这么一个问题,以下分析下原因: 当我在eclipse中选择Help-->Che ...
- Android Service 不被杀死并提高优先级
Android Service 不被杀死有两种思路,一种是将APP设置为系统应用.还有一种是增强service的生命力.即使屏幕背光关闭时也能执行. 因为设置为系统应用须要root.所以一般使用后一种 ...
- redis-3.0.3安装測试
$ tar xzvf redis-3.0.3.tar.gz $ cd redis-3.0.3 $ make //编译 编译完毕进行 $ make test 命令測试 得到例如以下错误信息: c ...
- HDU 5302(Connect the Graph- 构造)
Connect the Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...