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. 免费高端出辕营,横空出世惊鬼神 Excel插件:ExcelPower_Helper 0.41初出茅庐

    免费高端出辕营,横空出世惊鬼神 Excel插件:ExcelPower_Helper 0.41初出茅庐        隐鹤 倾心开发 2019.4.1 1.   引言 经过前后大约零零散散的一年的开发, ...

  2. Oracle查询字符串数据进行排序,以及去重复

    原本的的一张表,填写数据的字段为字符串varchar2类型,然后进行排序的时候,就会出现问题.会默直接默认判断为第一个数字9最大,而不判断整个数字的大小. 所以,就要用到TO_NUMBER函数 sel ...

  3. Django3 Django 路由分发,反向解析,2.0版本的path

    urls配置像Django 所支撑网站的目录.它的本质是URL与要为该URL调用的视图函数之间的映射表:你就是以这种方式告诉Django,对于客户端发来的某个URL调用哪一段逻辑代码对应执行. 1.简 ...

  4. PowerDesigner 批量添加字段

    Option Explicit Dim mdl ' the current model Set mdl = ActiveModel Dim Tab 'running table Dim col_1 D ...

  5. rk3128 手动挂载 U 盘

    2019-04-16 关键字: RK . 挂载.U盘 笔者手里有一块非常原生的运行 Android 4.4 操作系统的 RK3128 开发板.原生到各种功能模块都不能用的地步.今天就遇到一个不按常理出 ...

  6. Excel中最精确的计算年龄的公式

    身份证算年龄 假设A1是身份证号所在单元格 =IF(MONTH(NOW())<INT(MID(A1,11,2)),INT(YEAR(NOW())-INT(MID(A1,7,4)))-1,IF(M ...

  7. You Are the One HDU - 4283 (区间DP)

    Problem Description The TV shows such as You Are the One has been very popular. In order to meet the ...

  8. [NOI2017]泳池

    题目描述 有一个长为\(n\),高为1001的网格,每个格子有\(p\)的概率为1,\((1-p)\)的概率0,定义一个网格的价值为极大的全一矩形,且这个矩形的底要贴着网格的底,求这个网格的价值为\( ...

  9. mybatis 插入 含有美元符号($) 字符串 报 java.lang.IndexOutOfBoundsException: No group 2 的问题

    一:问题描述: 在springboot-security框架生成BCryptPasswordEncoder()方法生成加密后的密码后,带有$符号,导致新增用户的时候插入不了,报(IndexOutOfB ...

  10. axios 或 ajax 请求文件

    axios 或 ajax 请求文件 axios({ url: path + '/monitor/exportPicture' + '?access_token=' + getToken(), meth ...