[比赛链接]

http://codeforces.com/contest/922

[题解]

Problem A. Cloning Toys

         [算法]

当y = 0 ,   不可以

当y = 1 , x不为0时 , 不可以

当 y - 1 <= x , (x - y + 1)为偶数时 , 可以

时间复杂度 : O(1)

[代码]

#include<bits/stdc++.h>
using namespace std; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
} int main()
{ int x , y;
read(x); read(y);
if (y == ) printf("No\n");
else if (y == && x != ) printf("No\n");
else if (y - <= x && (x - y + ) % == ) printf("Yes\n");
else printf("No\n"); return ; }

Problem B. Magic Forest

              [算法]

枚举三角形的两边 , 计算第三边 , 判断是否能构成三角形即可

时间复杂度 : O(N^2)

[代码]

#include<bits/stdc++.h>
using namespace std; int n; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
inline bool ok(int x,int y,int z)
{
return x > && y > && z > && x <= n && y <= n && z <= n && x + y > z && x + z > y && y + z > x;
} int main()
{ int answer = ;
read(n);
for (int i = ; i <= n; i++)
{
for (int j = ; j <= n; j++)
{
int k = i ^ j;
if (ok(i,j,k)) answer++;
}
}
answer /= ;
printf("%d\n",answer); return ; }

Problem C. Cave Painting

                [算法]

一个数除以1余数只可能为0

一个数除以2余数只可能为0,1

....

一个数除以n余数只可能为0,1,2,...n - 1

因此 , 我们只需判断对于i <= k , n除以i余数是否余数(i - 1)

时间复杂度 : O(K)

[代码]

#include<bits/stdc++.h>
using namespace std;
typedef long long LL; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
} int main()
{ LL n , k;
read(n); read(k);
for (LL i = ; i <= k; i++)
{
if (n % i != i - )
{
printf("No\n");
return ;
}
}
printf("Yes\n"); return ; }

Problem D. Robot Vacuum Cleaner

                  [算法]

显然 , 答案只与字符串中"s"和"h"的个数有关

若a.s * b.h > a.h * b.s , a比b优

调用std :: sort即可 , 时间复杂度 : O(NlogN)

[代码]

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 1e5 + ; struct info
{
int s , h;
} a[MAXN]; int n; inline bool cmp(info a,info b)
{
return 1ll * a.s * b.h > 1ll * b.s * a.h;
} int main()
{ cin >> n;
LL ans = ;
for (int i = ; i <= n; i++)
{
string s;
cin >> s;
for (int j = ; j < (int)s.size(); j++)
{
if (s[j] == 'h')
{
a[i].h++;
ans += a[i].s;
} else a[i].s++;
}
}
sort(a + ,a + n + ,cmp);
int pre = ;
for (int i = ; i <= n; i++)
{
ans += 1ll * pre * a[i].h;
pre += a[i].s;
}
printf("%I64d\n",ans); return ; }

Problem E. Birds

                      [算法]

注意 .,考虑使用动态规划

用f[i][j]表示在前i只小鸟中选j只 , 最多还剩多少能量 , 转移比较显然 , 不再赘述

时间复杂度 : O(NV)

[代码]

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MAXN = 1e3 + ;
const LL MAXS = 1e4 + ;
const LL inf = 1e18; LL n , W , B , X;
LL c[MAXN],cost[MAXN];
LL dp[MAXN][MAXS]; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
int main()
{ read(n); read(W); read(B); read(X);
for (LL i = ; i <= n; i++) read(c[i]);
for (LL i = ; i <= n; i++) read(cost[i]);
for (LL i = ; i <= n; i++)
{
for (LL j = ; j < MAXS; j++)
{
dp[i][j] = -inf;
}
}
LL cnt = c[];
for (LL i = ; i <= c[]; i++)
{
if (W - 1LL * i * cost[] >= )
dp[][i] = min(W - 1LL * i * cost[] + X,W + i * B);
else break;
}
for (LL i = ; i <= n; i++)
{
cnt += c[i];
for (LL j = ; j <= cnt; j++)
{
for (LL k = ; k <= min(j,c[i]); k++)
{
if (dp[i - ][j - k] == -inf) continue;
if (dp[i - ][j - k] - 1LL * cost[i] * k >= )
chkmax(dp[i][j],min(1LL * W + 1LL * j * B,dp[i - ][j - k] + 1LL * X - 1LL * cost[i] * k));
}
}
}
LL ans = ;
for (LL i = ; i <= cnt; i++)
{
if (dp[n][i] >= )
ans = i;
}
printf("%I64d\n",ans); return ; }

Problem F.  Divisbility

[算法]

用F(i)表示选取1-i ,  符合条件的二元组的个数

显然 , 当k > F(n)时 ,  答案为No

否则 , 若k < F(n / 2) , 则不断将n降至n / 2

最后 , 我们取出n  / 2 + 1至n , 然后贪心删除一些数 , 即可

时间复杂度 : O(NlogN)

[代码]

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + ;
typedef long long LL; int n , k;
int d[MAXN];
vector< int > a[MAXN];
bool flg[MAXN]; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
inline LL f(int n)
{
LL ret = ;
for (int i = ; i <= n; i++) ret += 1LL * n / i - ;
return ret;
} int main()
{ read(n); read(k);
if (k > f(n))
{
printf("No\n");
return ;
}
while (f(n >> ) >= k) n >>= ;
for (int i = ; i <= n; i++)
{
for (int j = * i; j <= n; j += i)
{
++d[j];
}
}
for (int i = n / + ; i <= n; i++) a[d[i]].push_back(i);
memset(flg,true,sizeof(flg));
int m = f(n) - k;
for (int i = n; i >= ; i--)
{
for (unsigned j = ; j < (int)a[i].size(); j++)
{
if (m >= i)
{
m -= i;
flg[a[i][j]] = false;
}
}
}
int ans = ;
for (int i = ; i <= n; i++)
if (flg[i]) ans++;
printf("Yes\n%d\n",ans);
for (int i = ; i <= n; i++)
if (flg[i]) printf("%d ",i);
printf("\n"); return ; }

[Codeforces Round #461 (Div2)] 题解的更多相关文章

  1. CodeForces round 967 div2 题解(A~E)

    本来准备比完赛就写题解的, 但是一拖拖了一星期, 唉 最后一题没搞懂怎么做,恳请大神指教 欢迎大家在评论区提问. A Mind the Gap 稳定版题面 https://cn.vjudge.net/ ...

  2. Codeforces Round #407 div2 题解【ABCDE】

    Anastasia and pebbles 题意:你有两种框,每个框可以最多装k重量的物品,但是你每个框不能装不一样的物品.现在地面上有n个物品,问你最少多少次,可以把这n个物品全部装回去. 题解:其 ...

  3. Codeforces Round #467(Div2)题解

    凌晨起来打CF,0:05,也是我第一次codeforces 第一题: 我刚开始怀疑自己读错题了,怎么会辣么水. 判除了0的数字种类 #include <cstdio> ; ]; int m ...

  4. Codeforces Round#704 Div2 题解(A,B,C,D,E)

    FST ROUND !!1 A Three swimmers: 直接整除一下向上取整就好了: #include <bits/stdc++.h> using namespace std; t ...

  5. Codeforces Round#687 Div2 题解

    打这场的时候迷迷糊糊的,然后掉分了( A Prison Break: 题面很复杂,但是题意很简单,仅需求出从这个点到四个角的最大的曼哈顿距离即可 #include <bits/stdc++.h& ...

  6. CodeForces Round #516 Div2 题解

    A. Make a triangle! 暴力... 就是给你三个数,你每次可以选一个加1,问最少加多少次能构成三角形 #include <bits/stdc++.h> #define ll ...

  7. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  8. CF922 CodeForces Round #461(Div.2)

    CF922 CodeForces Round #461(Div.2) 这场比赛很晚呀 果断滚去睡了 现在来做一下 A CF922 A 翻译: 一开始有一个初始版本的玩具 每次有两种操作: 放一个初始版 ...

  9. Codeforces Round #543 Div1题解(并不全)

    Codeforces Round #543 Div1题解 Codeforces A. Diana and Liana 给定一个长度为\(m\)的序列,你可以从中删去不超过\(m-n*k\)个元素,剩下 ...

随机推荐

  1. [codeforces551E]GukiZ and GukiZiana

    [codeforces551E]GukiZ and GukiZiana 试题描述 Professor GukiZ was playing with arrays again and accidenta ...

  2. POJ1690 简单运算去括号

    题目大意: 给定一串只含加减和括号的运算,去掉没用的括号和空白字符输出 这里其实只要去找当前括号前面那个运算符是不是减号,如果是减号且这个括号内出现过运算符说明这个括号应该存在 #include &l ...

  3. [POJ1797] Heavy Transportation(最大生成树 || 最短路变形)

    传送门 1.最大生成树 可以求出最大生成树,其中权值最小的边即为答案. 2.最短路 只需改变spfa里面的松弛操作就可以求出答案. ——代码 #include <queue> #inclu ...

  4. 【网络流】codeforces C. Heidi and Library (hard)

    http://codeforces.com/contest/802/problem/C

  5. Catch The Caw——(广度优先搜索的应用,队列)

    抓住那头牛(POJ3278)农夫知道一头牛的位置,想要抓住它.农夫和牛都位于数轴上,农夫起始位于点N(0<=N<=100000),牛位于点K(0<=K<=100000).农夫有 ...

  6. msp430项目编程22

    msp430中项目---充电控制系统 1.定时器工作原理 2.电路原理说明 3.代码(显示部分) 4.代码(功能实现) 5.项目总结 msp430项目编程 msp430入门学习

  7. [Bzoj5177][Jsoi2013]贪心的导游(主席树)

    5177: [Jsoi2013]贪心的导游 Time Limit: 40 Sec  Memory Limit: 512 MBSubmit: 32  Solved: 15[Submit][Status] ...

  8. HDU 1896 【留个使用priority_queue容器的样例】

    感谢<啊哈!算法>的讲解,水鸟弄懂了什么是优先队列. 题意是:在路上有很多石子,给出他们的初始位置和小明能够将他们扔出的距离,当小明遇到奇数个石子的时候就会把它扔出,遇到偶数个就会忽略他, ...

  9. Springmvc 前台传递参数到后台需要数据绑定

    我们知道,当提交表单时,controller会把表单元素注入到command类里,但是系统注入的只能是基本类型,如int,char,String.但当我们在command类里需要复杂类型,如Integ ...

  10. linux是类unix操作系统

    linux是类unix操作系统,linux与unix使用的基础命令是一样的,没有区别.Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和UNIX的多用户.多任务.支持多线程 ...