水 A - Patrick and Shopping

#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;
}

  

贪心 C - Day at the Beach

预处理出前缀最大值和后缀最小值

#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)的更多相关文章

  1. 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/ ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. Codeforces Round #332 (Div. 2) D. Spongebob and Squares(枚举)

    http://codeforces.com/problemset/problem/599/D 题意:给出一个数x,问你有多少个n*m的网格中有x个正方形,输出n和m的值. 思路: 易得公式为:$\su ...

  6. Codeforces Round #332 (Div. 二) B. Spongebob and Joke

    Description While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. MongoDB 基础 -安全性-(权限操作)

    和其他所有数据库一样,权限的管理都差不多一样.mongodb存储所有的用户信息在admin 数据库的集合system.users中,保存用户名.密码和数据库信息.mongodb默认不启用授权认证,只要 ...

  2. 3ds max的动画输出

    转自:http://zhidao.baidu.com/link?url=qc3vV2A9-ydb-YiVKoF7z_bIIRlmLSkyl8DcuWNYn8FaBxa2BDVLwuGPX_jYWxbw ...

  3. NYOJ题目111分数加减法

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsEAAAKBCAIAAAA5i+FPAAAgAElEQVR4nO3dPXLbugMv7LsJ916Iay ...

  4. Android -- android.os.Parcelable[] cannot be cast to ...

    我本想直接把Bunde.getParcelableArray(...)得到的Parcelable[]强制转换为自定义类数组,但是失败了,网上找了两种解决办法: Parcelable[] data =b ...

  5. JS中级 - 01:DOM节点

    1元素属性   1.1childNodes 返回元素的一个子节点的数组 (不推荐,建议用非标准children代替) 提醒:只包含一级子节点,不包含后辈孙级别以下节点. children:返回元素的一 ...

  6. MySQL replace函数替换字符串语句的用法(mysql字符串替换)

    MySQL replace函数我们经常用到,下面就为您详细介绍MySQL replace函数的用法,希望对您学习MySQL replace函数方面能有所启迪. 最近在研究CMS,在数据转换的时候需要用 ...

  7. C++杂记

    变量就是一个地址,同进程内可以直接访问,要做好线程之间的同步就是了.——摘自CSDN 2015-06-18 16:58:10(注:注意变量的生命周期(作用域就可以不在意))

  8. 回溯法解决N皇后问题(以四皇后为例)

    以4皇后为例,其他的N皇后问题以此类推.所谓4皇后问题就是求解如何在4×4的棋盘上无冲突的摆放4个皇后棋子.在国际象棋中,皇后的移动方式为横竖交叉的,因此在任意一个皇后所在位置的水平.竖直.以及45度 ...

  9. 【JAVA多线程概述】

    一.多线程概述 一个进程中至少有一个线程,每一个线程都有自己运行的内容,这个内容可以称为线程要执行的任务. 不能没一个问题都使用多线程,能使用单线程解决的问题就不要使用多线程解决. 使用多线程的弊端: ...

  10. 【openGL】画直线

    #include "stdafx.h" #include <GL/glut.h> #include <stdlib.h> #include <math ...