Codeforces Round #332 (Div. 2)
#include <bits/stdc++.h>
using namespace std; int main(void) {
int d1, d2, d3;
scanf ("%d%d%d", &d1, &d2, &d3);
printf ("%d\n", min (min (2 * (min (d1, d2) + d3), 2 * (d1 + d2)), d1 + d2 + d3)); return 0;
}
构造(坑) B - Spongebob and Joke
题目不难,但是有坑点:如果可能Ambiguity的话不能直接break,因为可能是Impossible
#include <bits/stdc++.h>
using namespace std; const int N = 1e5 + 5;
int a[N], f[N], b[N];
struct Pos {
int cnt, id;
}p[N]; int main(void) {
int n, m; scanf ("%d%d", &n, &m);
for (int i=1; i<=n; ++i) {
scanf ("%d", &f[i]);
p[f[i]].cnt++; p[f[i]].id = i;
}
for (int i=1; i<=m; ++i) {
scanf ("%d", &b[i]);
}
int ans = 0; //-1 Impossible 1 Ambiguity 0 Possible
for (int i=1; i<=m; ++i) {
if (p[b[i]].cnt == 0) {
ans = -1; break;
}
else if (p[b[i]].cnt > 1) {
ans = 1; //break;
}
else {
a[i] = p[b[i]].id;
}
}
if (ans == -1) puts ("Impossible");
else if (ans == 1) puts ("Ambiguity");
else {
puts ("Possible");
for (int i=1; i<=m; ++i) {
printf ("%d%c", a[i], i == m ? '\n' : ' ');
}
} return 0;
}
预处理出前缀最大值和后缀最小值
#include <bits/stdc++.h>
using namespace std; const int N = 1e5 + 5;
int a[N];
int pmx[N], pmn[N]; inline int Max(int a, int b) {
if (a > b) return a;
else return b;
} inline int Min(int a, int b) {
if (a < b) return a;
else return b;
} int main(void) {
int n; scanf ("%d", &n);
for (int i=1; i<=n; ++i) {
scanf ("%d", &a[i]);
pmx[i] = Max (pmx[i-1], a[i]);
//printf ("i: %d mx: %d\n", i, pmx[i]);
}
pmn[n+1] = 0x3f3f3f3f;
for (int i=n; i>=1; --i) {
pmn[i] = Min (pmn[i+1], a[i]);
//printf ("i: %d mx: %d\n", i, pmx[i]);
}
if (n == 1) {
puts ("1"); return 0;
}
int ans = 0, i = 1;
while (i < n) {
while (i < n && pmx[i] > pmn[i+1]) {
i++;
}
//printf ("now: %d\n", i);
if (i == n) {
ans++; break;
}
else {
ans++; i++;
if (i == n) {
ans++; break;
}
}
}
printf ("%d\n", ans); return 0;
}
找规律+暴力 D - Spongebob and Squares
题意:问有x个不同的正方形的方案数
分析:x = n * m + (n - 1) * (m -1) + ... + 1 * (m - (n-1)) = (-n^3 + 3mn^2 + (3m+1)*n ))/ 6, 可以想象成2 * 2的正方形比1*1的在行上少了1种可能,在列上也少了1种可能,以此类推.然后暴力枚举判断
#include <bits/stdc++.h>
using namespace std; typedef long long ll; ll get_m(ll x, ll n) {
ll ret = (2 * x + (n * n * n - n) / 3) / (n * n + n);
return ret;
} ll cal(ll n, ll m) {
ll ret = -n * n * n + 3 * (n * n + n) * m + n;
ret /= 6;
return ret;
} int main(void) {
set<pair<ll, ll> > S;
ll x; scanf ("%lld", &x);
for (ll i=1; i<=3000000; ++i) {
ll m = get_m (x, i);
if (m < i) break;
if (cal (i, m) == x) {
S.insert (make_pair (i, m));
if (i != m) {
S.insert (make_pair (m, i));
}
}
}
set<pair<ll, ll> >::iterator it;
printf ("%d\n", (int) S.size ());
for (it=S.begin (); it!=S.end (); ++it) {
printf ("%lld %lld\n", it->first, it->second);
} return 0;
}
Codeforces Round #332 (Div. 2)的更多相关文章
- Codeforces Round #332 (Div. 2) D. Spongebob and Squares 数学题枚举
D. Spongebob and Squares Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...
- Codeforces Round #332 (Div. 2) C. Day at the Beach 线段树
C. Day at the Beach Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/599/p ...
- Codeforces Round #332 (Div. 2) B. Spongebob and Joke 水题
B. Spongebob and Joke Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/599 ...
- Codeforces Round #332 (Div. 2) A. Patrick and Shopping 水题
A. Patrick and Shopping Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- Codeforces Round #332 (Div. 2) D. Spongebob and Squares(枚举)
http://codeforces.com/problemset/problem/599/D 题意:给出一个数x,问你有多少个n*m的网格中有x个正方形,输出n和m的值. 思路: 易得公式为:$\su ...
- Codeforces Round #332 (Div. 二) B. Spongebob and Joke
Description While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. ...
- Codeforces Round #332 (Div. 2)_B. Spongebob and Joke
B. Spongebob and Joke time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #332 (Div. 2)B. Spongebob and Joke
B. Spongebob and Joke time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #332 (Div. 2)D. Spongebob and Squares 数学
D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calcula ...
随机推荐
- 微信支付官方.net版之坑你没商量
最近开始弄支付这块,先是支付宝手机网站支付,也是坑了我许久,不过还好,问题不大. 让我们看看微信支付有多少坑 微信商户平台,你们知道么(我前天才知道,别笑我) 登录地址:https://mch.wei ...
- WEB前端开发学习:源码canvas 雪
WEB前端开发学习:源码canvas 雪 双旦节要到了,程序员们为了响应气氛,特别用代码制作了动态雪花,WEB前端开发学习的初学者们一起跟着案例做一遍吧! <!DOCTYPE html> ...
- jvm分析
是什么 jps 查看所有的jvm进程,包括进程ID,进程启动的路径等等. jstack 观察jvm中当前所有线程的运行情况和线程当前状态. 系统崩溃了?如果java程序崩溃生成core文件,j ...
- 资源监控工具--spotlight
1.被监控服务器为Ubuntu server,先在服务器上创建一个用户,专门用于监控使用! 因为远程监控服务器,需要获取服务器的资源,所以必须要有权限.使用文档明确说明,不能使用root用户,但是我用 ...
- C#学习笔记--详解委托,事件与回调函数
.Net编程中最经常用的元素,事件必然是其中之一.无论在ASP.NET还是WINFrom开发中,窗体加载(Load),绘制(Paint),初始化(Init)等等.“protected void Pag ...
- python多线程之Condition(条件变量)
#!/usr/bin/env python # -*- coding: utf-8 -*- from threading import Thread, Condition import time it ...
- hdu 1556:Color the ball(第二类树状数组 —— 区间更新,点求和)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- Acdream 1111:LSS(水题,字符串处理)
LSS Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 128000/64000 KB (Java/Others) SubmitStati ...
- HTML5+CSS3的响应式网页设计:自动适应屏幕宽度
这几天都在修改博客上面的样式.本来用的是d83.0的模板.自己又修改了许多地方,其中自己修改的一些地方在手机里面显示的效果不是很理想,于是想改成自适应的效果.对CSS3不是特别的熟练,只能去网上找找案 ...
- Linux环境下使用C/C++编写CGI(httpd)
step1下载: ftp://ftp.gnu.org/gnu/cgicc/ step2: tar xzf cgicc-X.X.X.tar.gz(用最新版本) cd cgicc-X.X.X ./conf ...