Codeforces Round #352 (Div. 2) (A-D)
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;
}
Codeforces Round #352 (Div. 2) (A-D)的更多相关文章
- Codeforces Round #352 (Div. 2) C. Recycling Bottles 暴力+贪心
题目链接: http://codeforces.com/contest/672/problem/C 题意: 公园里有两个人一个垃圾桶和n个瓶子,现在这两个人需要把所有的瓶子扔进垃圾桶,给出人,垃圾桶, ...
- Codeforces Round #352 (Div. 2) D. Robin Hood
题目链接: http://codeforces.com/contest/672/problem/D 题意: 给你一个数组,每次操作,最大数减一,最小数加一,如果最大数减一之后比最小数加一之后要小,则取 ...
- Codeforces Round #352 (Div. 2) D. Robin Hood (二分答案)
题目链接:http://codeforces.com/contest/672/problem/D 有n个人,k个操作,每个人有a[i]个物品,每次操作把最富的人那里拿一个物品给最穷的人,问你最后贫富差 ...
- 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 ...
- Codeforces Round #352 (Div. 1) A. Recycling Bottles 暴力
A. Recycling Bottles 题目连接: http://www.codeforces.com/contest/671/problem/A Description It was recycl ...
- 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 ...
- Codeforces Round #352 (Div. 2) A. Summer Camp 水题
A. Summer Camp 题目连接: http://www.codeforces.com/contest/672/problem/A Description Every year, hundred ...
- Codeforces Round #352 (Div. 2) ABCD
Problems # Name A Summer Camp standard input/output 1 s, 256 MB x3197 B Different is Good ...
- Codeforces Round #352 (Div. 2)
模拟 A - Summer Camp #include <bits/stdc++.h> int a[1100]; int b[100]; int len; void init() { in ...
- 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 ...
随机推荐
- WMI测试器
WMI是... 来自百度百科:WMI(Windows Management Instrumentation,Windows 管理规范)是一项核心的 Windows 管理技术:用户可以使用 WMI 管理 ...
- 判断一个点是否在某个区域内。百度,高德,腾讯都能用。(php版)
<?php // *** 配置文件(表示区域的三维数组)其内的点,必须按顺时针方向依次给出! $area = array( // 天通苑店 0 => array( array('x'=&g ...
- XPath、CSS 选择器 -学习地址
http://www.w3school.com.cn/cssref/css_selectors.asp http://www.w3school.com.cn/xpath/xpath_syntax.as ...
- for循环增强
for(声明语句 : 表达式) { //代码句子 } 声明语句:声明新的局部变量,该变量的类型必须和数组元素的类型匹配.其作用域限定在循环语句块,其值与此时数组元素的值相等. 表达式:表达式是要访问的 ...
- Git中.gitignore文件不起作用的解决以及Git中的忽略规则介绍
在Studio里使用Git管理代码的过程中,可以修改.gitignore文件中的标示的方法来忽略开发者想忽略掉的文件或目录,如果没有.gitignore文件,可以自己手工创建.在.gitignore文 ...
- SaltStack说明文档
SaltStack说明文档 master安装 # 安装 yum -y install salt-master salt-minion salt-ssh # 启动 systemctl start sal ...
- 不转实体直接获取Json字符串中某个字段的值
JObject jo = (JObject)JsonConvert.DeserializeObject(JsonStr);//JsonStr 为Json字符串 string lng = jo[&quo ...
- POJ1988 Cube stacking(非递归)
n有N(N<=30,000)堆方块,开始每堆都是一个方块.方块编号1 – N. 有两种操作: nM x y : 表示把方块x所在的堆,拿起来叠放到y所在的堆上. nC x : 问方块x下面有多少 ...
- python自动启动appium服务
我们可以通过socket模块来检查appium是否启动,如果未启动,可以通过subprocess模块来启动,需要导入socket和subprocess模块,具体如下图: 第1个函数:表示检查appiu ...
- linux下python安装
下载包: wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tar.gz 解压安装: tar -zvxf Python-3.6.3. ...