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 ...
随机推荐
- java课后作业
课后作业之字串加密: 设计思想: 1.输入要加密的英文子串str 2.定义num=str的字符串长度 3.将字符串转化为单个字符 4.每个字符+3,向后移3个 5.定义str1,将新得到的每个字符加到 ...
- [Android Pro] Android 进程级别 和 oom_adj对应关系
一 : 前台进程 (Active Process): oom_adj为0. 前台进程包括 : 1 : 活动 正在前台接收用户输入 2:活动.服务与广播接收器正在执行一个onReceive事件的处理函数 ...
- August 7th 2016, Week 33rd Sunday
Knowing yourself is the height of wisdom. 了解自己就是大智慧. Two-day holiday, even I didn't have enought tim ...
- 常用shell命令操作
1.找出系统中所有的*.c 和*.h 文件 (-o 或者) $find / -name "*.cpp" -o -name "*.h" 2.设定 eth0 的 I ...
- Codeforces Round #377 (Div. 2)D(二分)
题目链接:http://codeforces.com/contest/732/problem/D 题意: 在m天中要考k个课程, 数组a中有m个元素,表示第a[i]表示第i天可以进行哪门考试,若a[i ...
- 《Thinking in Java》十七章_容器深入研究_练习13(Page484)
练习13: 单词计数器 import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFou ...
- mysql常用表/视图管理语句
查看所有表 show tables; 查看表/视图结构 desc 表名/视图名: 查看建表过程 show create table 表名: 查看建视图过程 show create view 视图名 ...
- Java -- 访问控制
原文:http://www.cnblogs.com/diyingyun/archive/2011/12/21/2295947.html 可见/访问性 在同一类中 同一包中 不同包中 同一包子类中 ...
- C#学习笔记----AppDomain应用程序域
使用.Net建立的可执行程序*.exe,并没有直接承载到进程当中,而是承载到应用程序域(AppDomain)当中.应用程序域是.Net引入的一个新概念,它比进程所占用的资源要少,可以被看做是一个轻量级 ...
- 重温WCF之会话Session(九)
转载地址:http://blog.csdn.net/tcjiaan/article/details/8281782 每个客户端在服务器上都有其的独立数据存储区,互不相干,就好像A和服务器在单独谈话一样 ...