672A Summer Camp

题意:

1-n数字连成一个字符串, 给定n , 输出字符串的第n个字符。n 很小, 可以直接暴力。

Code:

#include <bits/stdc++.h>
using namespace std; int main() {
int n;
cin >> n;
int begin = 1;
for(;;)
{
int dig = log10(begin) + 1;
if(n <= dig)
{
char ss[10];
sprintf(ss, "%d", begin);
cout << ss[n-1] << endl;
break;
}
else {
begin ++;
n -= dig;
}
}
return 0;
}

672B Different is Good

题意:

给定一个字符串, 可以对字符串进行单个字符的修改, **要求所有子串都不相同**
所以每个字符都不能相同。

Code:

#include <bits/stdc++.h>
using namespace std;
int Sum[50];
int main() {
memset(Sum, 0, sizeof(Sum));
int n;
string s;
cin >> n >> s;
int Count = 0;
int Vis = 0;
for(int i = 0; i < s.length(); ++i)
{
int c = s[i]-'a';
Sum[c]++;
}
for(int i = 0; i < 26; ++i)
{
if(Sum[i]) Vis++;
if(Sum[i] > 1) Count += Sum[i] - 1;
}
int ANS = 0;
if(Count > (26 - Vis)) ANS = -1;
else ANS = Count;
cout << ANS << endl;
}

671A Recycling Bottles

题意:

有A , B两人, 垃圾桶T点, 坐标系中还有 n 个垃圾桶。
A,B两人去捡垃圾, 把垃圾放入垃圾桶中, 一次一个, 输出A,B两人的最短行走路线。
(A,B)并不是都要去捡, 可以只有一个人。
直接进行贪心就可以得出结果了。

Code:

#include <bits/stdc++.h>

using namespace std;
const double eps = 1e-8;
typedef long long LL;
const int maxn = 1e5 + 131;
struct Point {
LL x, y;
} ;
Point A, B, T;
Point Num[maxn];
int n; double Distance(Point a, Point b) {
return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
} double Dis_T[maxn], Dis_A[maxn], Dis_B[maxn];
double GetIn() {
double Sum = 0.0;
cin >> A.x >> A.y >> B.x >> B.y >> T.x >> T.y;
cin >> n;
for(int i = 0; i < n; ++i)
{
cin >> Num[i].x >> Num[i].y;
Dis_T[i] = Distance(Num[i], T);
Dis_A[i] = Distance(Num[i], A);
Dis_B[i] = Distance(Num[i], B);
Sum += (Dis_T[i] * 2);
}
//总距离是在 2倍Dis_T 的基础上修改的。
return Sum;
} int main() {
double S ,Sum;
S = Sum = GetIn();
double MinA = 1e12, MinB = 1e12;
int posA = 0, posB = 0;
for(int i = 0; i < n; ++i)
{
if(Dis_A[i]-Dis_T[i] < MinA) // 找出 A 点最短的第一次捡垃圾路线
{
MinA = Dis_A[i]-Dis_T[i];
posA = i;
}
if(Dis_B[i]-Dis_T[i] < MinB) // 同理 B 点。
{
MinB = Dis_B[i]-Dis_T[i];
posB = i;
}
}
if(MinA < 0 && MinB < 0) { // 小于 0 则说明 Dis_A + Dis_T <2 * Dis_T 的;
if(posA == posB) {
S = min(S, Sum-Dis_T[posA]+Dis_A[posA]); //只有A 捡垃圾的情况
S = min(S, Sum-Dis_T[posB]+Dis_B[posB]); //只有B 捡垃圾的情况
for(int i = 0; i < n; ++i) if(i != posA)
S = min(S, Sum-Dis_T[posA]+Dis_A[posA]-Dis_T[i]+Dis_B[i]);
for(int i = 0; i < n; ++i) if(i != posB)
S = min(S, Sum-Dis_T[posB]+Dis_B[posB]-Dis_T[i]+Dis_A[i]);
}
else {
S = Sum + MinA + MinB;
}
}
else {
if(MinA < MinB)
S = Sum - Dis_T[posA]+Dis_A[posA];
else
S = Sum - Dis_T[posB]+Dis_B[posB];
}
printf("%.12f\n",S);
return 0;
}

671B Robin Hood

题意:

给一组序列, 有一个人, 每天会把序列的最大值 -1, 最小值 +1;
如果序列都相同, 不做任何动作。
输出 K 天后 序列的 Max - Min;
也是贪心。

Code:

#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
const int maxn = 5000000 + 131;
LL City[maxn];
LL n, k;
int main() {
std::ios::sync_with_stdio(false);
cin >> n >> k;
LL Sum = 0;
for(int i = 0; i < n; ++i) cin >> City[i], Sum += City[i];
sort(City, City+n);
LL Min = City[0], Max = City[n-1];
LL Use = k;
for(int i = 1; i < n; ++i) if(City[i] > Min) { //先把小的值一起抬高
LL temp = min(City[i]-Min, Use/LL(i));
Min += temp;
Use -= temp * i;//总共消耗的天数。
/* 这里Use 有余下, 也不会对 Max - Min 造成影响,*/
}
Use = k;
for(int i = n-2; i >= 0; --i) if(City[i] < Max) {
LL temp = min(Max-City[i], Use/LL(n-i-1));
Max -= temp;
Use -= temp * (n-i-1);
} LL Ans = Sum % n ? 1 : 0;
Ans = max(Ans, Max - Min);
cout << Ans <<endl;
return 0;
}

E 题

Codeforces Round #352 (Div. 2) (A-D)的更多相关文章

  1. Codeforces Round #352 (Div. 2) C. Recycling Bottles 暴力+贪心

    题目链接: http://codeforces.com/contest/672/problem/C 题意: 公园里有两个人一个垃圾桶和n个瓶子,现在这两个人需要把所有的瓶子扔进垃圾桶,给出人,垃圾桶, ...

  2. Codeforces Round #352 (Div. 2) D. Robin Hood

    题目链接: http://codeforces.com/contest/672/problem/D 题意: 给你一个数组,每次操作,最大数减一,最小数加一,如果最大数减一之后比最小数加一之后要小,则取 ...

  3. Codeforces Round #352 (Div. 2) D. Robin Hood (二分答案)

    题目链接:http://codeforces.com/contest/672/problem/D 有n个人,k个操作,每个人有a[i]个物品,每次操作把最富的人那里拿一个物品给最穷的人,问你最后贫富差 ...

  4. Codeforces Round #352 (Div. 1) B. Robin Hood 二分

    B. Robin Hood 题目连接: http://www.codeforces.com/contest/671/problem/B Description We all know the impr ...

  5. Codeforces Round #352 (Div. 1) A. Recycling Bottles 暴力

    A. Recycling Bottles 题目连接: http://www.codeforces.com/contest/671/problem/A Description It was recycl ...

  6. Codeforces Round #352 (Div. 2) B. Different is Good 水题

    B. Different is Good 题目连接: http://www.codeforces.com/contest/672/problem/B Description A wise man to ...

  7. Codeforces Round #352 (Div. 2) A. Summer Camp 水题

    A. Summer Camp 题目连接: http://www.codeforces.com/contest/672/problem/A Description Every year, hundred ...

  8. Codeforces Round #352 (Div. 2) ABCD

    Problems     # Name     A Summer Camp standard input/output 1 s, 256 MB    x3197 B Different is Good ...

  9. Codeforces Round #352 (Div. 2)

    模拟 A - Summer Camp #include <bits/stdc++.h> int a[1100]; int b[100]; int len; void init() { in ...

  10. Codeforces Round #352 (Div. 2) B - Different is Good

    A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to b ...

随机推荐

  1. pydoc用法

    pydoc是python自带的一个文档生成工具,使用pydoc可以很方便的查看类和方法结构   本文主要介绍:1.查看文档的方法.2.html文档说明.   一.查看文档的方法 方法1:启动本地服务, ...

  2. NodeJs操作MongoDB之分页功能与常见问题

    NodeJs操作MongoDB之分页功能与常见问题 一,方法介绍 1,聚合操作之count count()方法可以查询统计符合条件的集合的总数 db.User.count(<query>) ...

  3. springboot+shiro 一个项目部署多个,session名冲突问题

    问题 前几天遇到一个比较奇怪的问题, 一个项目部署多个,端口不同.启动之后在同一浏览器中进行登录,后一个登录的会把前一个登录的挤掉,导致只能登录一个. 原因 是因为sessionid相同,然后修改了s ...

  4. python3 整数类型PyLongObject 和PyObject源码分析

    python3 整数类型PyLongObject 和PyObject源码分析 一 测试环境介绍和准备 测试环境: 操作系统:windows10 Python版本:3.7.0 下载地址 VS版本:vs2 ...

  5. Linux C Socket简单实例与详细注释

    最近做的东西与socket十分紧密,所以很好奇它具体是如何实现的,以前也有了解过,但是又忘记了,于是把它记录下来,以便日后查看. 服务器端:server.c #include <sys/type ...

  6. [BJOI2019]排兵布阵——分组背包

    题目链接: [BJOI2019]排兵布阵 对于每座堡垒,将$s$个对手排序,显然如果安排的兵力能打败第$i$个对手就一定能打败前$i-1$个. 那么对于第$i$座城堡,可以看做有$s+1$个物品(可以 ...

  7. 偏差-方差均衡(Bias-Variance Tradeoff)

    众所周知,对于线性回归,我们把目标方程式写成:. (其中,f(x)是自变量x和因变量y之间的关系方程式,表示由噪音造成的误差项,这个误差是无法消除的) 对y的估计写成:. 就是对自变量和因变量之间的关 ...

  8. 题解:luoguP1861 星之器

    为什么全世界都说这是个物理题,不应该是一个数学题吗,神犇的势能完全看不懂 我们直接来看题,对于一个点,在计算时候横坐标和纵坐标互不影响,所以我们分开考虑. 我们记两个点假如横坐标相同,分别记纵坐标为a ...

  9. Numpy的学习

    Numpy numpy(Numerical Python extensions)是一个第三方的Python包,用于科学计算.这个库的前身是1995年就开始开发的一个用于数组运算的库.经过了长时间的发展 ...

  10. (二分查找 拓展) leetcode 162. Find Peak Element && lintcode 75. Find Peak Element

    A peak element is an element that is greater than its neighbors. Given an input array nums, where nu ...