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

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  2. Qt 安装一个Service

    QString command = "sc create YourServiceName binPath= \""+application_path+"\&qu ...

  3. js中我的注释规范

    模块功能描述说明: /** * ------------------------------------------------------------------ * 模块描述说明 * ------ ...

  4. URL重写

    http://localhost:37977/UrlWrite.ashx?id=9URL重写成下面的访问方式,有利于SEO搜索引擎http://localhost:37977/UrlWrite-8.a ...

  5. 初学iPad开发入门

    iPad是一款苹果公司于2010年发布的平板电脑定位介于苹果的智能手机iPhone和笔记本电脑MacBook产品之间跟iPhone一样,搭载的是iOS操作系统 iPhone和iPad开发的区别 屏幕的 ...

  6. UVA 10192 Vacation

    裸最长公共子序列 #include<time.h> #include <cstdio> #include <iostream> #include<algori ...

  7. AngularJS模型 ng-model 指令

    ng-model 指令用于绑定应用程序数据到 HTML 控制器(input, select, textarea)的值. ng-model 指令可以将输入域的值与 AngularJS 创建的变量绑定.例 ...

  8. ASP.NET MVC中的Global.asax文件

    1.global.asax文件概述 global.asax这个文件包含全局应用程序事件的事件处理程序.它响应应用程序级别和会话级别事件的代码. 运行时, Global.asax 将被编译成一个动态生成 ...

  9. C#的lock关键字

    using System; using System.Threading; namespace Test { class Program { //一.Lock定义 //lock 关键字可以用来确保代码 ...

  10. mipi和dsi

    转自: http://blog.csdn.net/longxiaowu/article/details/24410021 一.MIPI MIPI(移动行业处理器接口)是Mobile Industry ...