CODEFORCE 672 题解(ABC)
来源:互联网 发布:数控铣好看编程图案 编辑:程序博客网 时间:2024/06/06 09:23
ROUND 672 题解(ABC)
A题题目
输入一个N 求第N个字符 简单的字符串问题 直接贴代码
#include <vector>#include <list>#include <map>#include <set>#include <deque>#include <queue>#include <stack>#include <bitset>#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <complex>#include <sstream>#include <iostream>#include <iomanip>#include <cstdio>#include <cmath>#include <cstdlib>#include <cstring>#include <ctime>#include <cassert>using namespace std;#define maxn 100005#define ll long long#define inf 2147483647#define INF 9223372036854775807#define pi acos(-1)const double eps=1e-9;string s;string l;void pre(){ for(int i=1;i<=1000;i++) { int k=i; l=""; while(k>0) { l+=k%10+'0'; k/=10; } for(int j = l.length()-1;j>=0;j--) { s+=l[j]; } }}int main(){ pre(); int n; while(cin >> n) cout << s[n-1] << endl;}
B题题目
字符串问题 给你一个长度为n的字符串 问你改变几个字符能让所有字串全不相同
考虑极限情况即可 所有的单个字母都为字串 只需要统计每个一个字母的个数
#include <vector>#include <list>#include <map>#include <set>#include <deque>#include <queue>#include <stack>#include <bitset>#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <complex>#include <sstream>#include <iostream>#include <iomanip>#include <cstdio>#include <cmath>#include <cstdlib>#include <cstring>#include <ctime>#include <cassert>using namespace std;#define maxn 100005#define ll long long#define inf 2147483647#define INF 9223372036854775807#define pi acos(-1)const double eps=1e-9;string s;string l;char a[maxn];int main(){ int n,i; while(cin >> n) { getchar(); gets(a); int sum= 1; if(n>26) cout << -1 << endl; else { sort(a,a+n); for(i=1;i<n;i++) { if(a[i-1]!=a[i]) sum++; printf("%d",sum); } cout << n-sum << endl; } }}
C题题目
给出A B两人位置 和垃圾桶位置 同时还有N个垃圾的位置
问你拾完所有垃圾 需要的最少路程
因为剪完垃圾都会回到垃圾桶的位置
所以 只需要考虑第一次去捡垃圾的情况
先算出所有垃圾到垃圾桶的位置再乘2
然后再遍历求出 A B到垃圾的位置 与垃圾桶位置的差值
再用总路程减去即可
第一次拾垃圾可以分为三种情况
1、A B 都有离垃圾近的这种情况 并且不是离同一个垃圾
2、A B 都有离垃圾近的这种情况 并且是同一个垃圾
3、只有A或者B有离垃圾近的情况
4、A B都比垃圾桶离垃圾远
1 这种情况 应该算出一个离垃圾最短值 和次短值 然后用 A的最短值+B的次短值和B的最短值+A的次短值比较大小 取较小的
2 即A加B最短值
3则让又最短值那个一直是垃圾 另外一个永远休息
4 取比较不远那个一直拾垃圾 另外一个休息
代码如下
#include <vector>#include <list>#include <map>#include <set>#include <deque>#include <queue>#include <stack>#include <bitset>#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <complex>#include <sstream>#include <iostream>#include <iomanip>#include <cstdio>#include <cmath>#include <cstdlib>#include <cstring>#include <ctime>#include <cassert>using namespace std;#define maxn 100005#define ll long long#define inf 2147483647#define INF 9223372036854775807#define db doubleint i,m,n;struct pos { int x,y;}a,b,t,c[maxn];double dis(pos xx,pos yy){ double dist = 0; dist = (db(xx.x-yy.x)*(xx.x-yy.x)+(db)(xx.y-yy.y)*(xx.y-yy.y)); dist = sqrt(dist); return dist;}int main(){ while(cin >>a.x >> a.y >> b.x >> b.y >>t.x >>t.y) { cin >> n; db sum=0; for(i=1;i<=n;i++) { cin >> c[i].x >> c[i].y; sum +=2* dis(c[i],t); } db maa=0; db mab=0; double daa,dbb; double ma=1e20; db mb=1e20 ; int flaga=0; int flagb=0; for(i=1;i<=n;i++) { daa = dis(a,c[i])-dis(c[i],t); dbb = dis(b,c[i])-dis(c[i],t); if(daa<maa) { ma = maa; maa = daa; flaga = i; } else if(daa < ma) { ma = daa; } if(dbb < mab) { mb = mab; mab = dbb; flagb = i; } else if(dbb < mb) { mb = dbb; } } double temp = 0; if(flaga&&flagb) { if(flaga==flagb) { temp+=min(maa+mb,mab+ma); } else { temp+=maa; temp+=mab; } } else if(flaga>0||flagb>0) { if(flaga>0) { temp+=maa; } if(flagb>0) { temp+=mab; } } else { temp+=min(ma,mb); } printf("%.12lf\n",sum+temp); }}
0 0
- CODEFORCE 672 题解(ABC)
- codeforce #381 ABC题解
- codeforce 387 (abc)水题
- 【bestcoder #34】ABC题解
- 【bestcoder #37】ABC题解
- Codeforces Round #428 (Div. 2) 题解(ABC)
- codeforce 259C 最新题解 第二场
- codeforce 259A 最新题解 第二场
- Codeforce 527D Clique Problem题解
- CodeForce #429 DIV2 A B C题解
- Codeforce Round #439 A B C 题解
- 【codeforces #295(div 1)】ABC题解
- 【codeforces #292(div 1)】ABC题解
- 【codeforces #290(div 1)】ABC题解
- 【codeforces #284(div 1)】ABC题解
- 【codeforces #283(div 1)】ABC题解
- 【codeforces #299(div 1)】ABC题解
- [Codeforces Round #309 (Div. 2)] #ABC题解
- bzoj 3396(最小割)
- 八大排序之快速排序
- Bitmap的高效加载
- Eclipse快捷键
- CAFFE学习笔记(三)在VS2013下生成需要的exe文件
- CODEFORCE 672 题解(ABC)
- 身边的素质教育
- HDU 3849 By Recognizing These Guys, We Find Social Networks Useful 边双连通
- Java三大布局介绍
- 基因治疗抗衰老首获成功:减轻肌肉质量及干细胞损耗
- leetcode reconstruct-itinerary
- Bootstrap3 多个模态对话框无法显示的问题
- I00013 鸡兔同笼
- Fresco 专为ANDROID加载图片(简单使用)