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. [转帖]Oracle 各个版本的升级路线图

    从oracle 7开始(甚至更早版本)到oracle 9iR2. 来源: https://blog.csdn.net/cymm_liu/article/details/11647533 http:// ...

  2. Windows 下使用 工具修改文件的 时间

    1. 下载工具 https://www.cr173.com/soft/12992.html 2. 使用工具修改即可 3. 忘记了东西处理挺方便的.  尤其是往前改日期的时候.

  3. HashMap源码解读(jdk1.8)

    1.相关常量 默认初始化容量(大小) static final int DEFAULT_INITIAL_CAPACITY = 1 << 4; 最大容量 static final int M ...

  4. golang项目练习

    一.记账系统 1.该软件能够记录收入.支出,并能够打印收支明细表 2. 代码 package main import ( . "fmt" ) func menu() string{ ...

  5. springboot实现简单的文件上传

    承接上一篇,这里记录一下简单的springboot文件上传的方式 首先,springboot简单文件上传不需要添加额外的jar包和配置 这里贴一下后端controller层的实现代码 补一份前台的HT ...

  6. Python Spider - urllib.request

    import urllib.request import urllib.parse import json proxy_support = urllib.request.ProxyHandler({' ...

  7. 使用TCP取样器测试Socket接口

    1 JMeter下载安装 下载地址:JMeter,选择Binaries下面的zip包. 检查java环境,是否安装了jdk或者jre. 解压zip包->找到bin目录下jmeter.bat文件- ...

  8. P1744 采购特价商品

    原题链接 https://www.luogu.org/problemnew/show/P1744 一道最短路的模板题.....很简单吧 求最短路的方法有很多,但是对于刚学完Floyd的我,只会用这个. ...

  9. ubuntu 安装 evpp

    ubuntu 安装 evpp 来源 https://www.cnblogs.com/wisdomyzw/p/9402440.html Ubuntu虚拟机安装开源库evpp说明: EVPP为奇虎360基 ...

  10. [File transfer]Syncthing

    https://syncthing.net/ 另外两种1.filezila 2.python -m http