Codeforces Round#2
A. Winner
题目大意:一些人在玩游戏,给出n次某人获得的分数,现在请计算出胜者,如果不止一个最高分,则取最先达到该分数的人。
题解:模拟得分过程,首先计算出最高分,然后获取先到达或超过最高分的人。
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <map>
using namespace std;
vector<string> name;
vector<int> score;
map<string,int> sum,sum1;
int Max=0,x;
string s;
int main(int n){
scanf("%d",&n);
for(int i=0;i<n;i++){
cin>>s>>x;
name.push_back(s);
score.push_back(x);
sum[name[i]]+=score[i];
}for(int i=0;i<n;i++){if(sum[name[i]]>Max)Max=sum[name[i]];}
for(int i=0;i<n;i++){
if(sum[name[i]]<Max||(sum1[name[i]]+=score[i])<Max)continue;
cout<<name[i]<<endl; break;
}
}
B. The least round way
题目大意:找一条从给出的数字矩阵左上角到右下角的道路,使得该路上所有数字的乘积后面的0最少。求出路径和最小的0数目。
题解:首先如果路径中有0,那么答案就是1,否则就是道路中数字中因子2和因子5的最小值(因为2和5配对才可以产生0),计算2和5的个数的过程用记忆化搜索,路径记录则由已知的DP值倒推获得。
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int N=1005;
const int inf=~0U>>2;
int dp[N][N],M[N][N],b[N][N],ans=inf,n;
string road;
void dfs(int x,int y){
if(x&&dp[x][y]==b[x][y]+dp[x-1][y]){dfs(x-1,y);road.push_back('D');}
else if(y){dfs(x,y-1);road.push_back('R');}
}
void solve(int c){
rep(i,n)rep(j,n){int x=0;while(M[i][j]&&M[i][j]%c==0)M[i][j]/=c,x++;b[i][j]=x;}
rep(i,n)rep(j,n){
if(i)dp[i][j]=b[i][j]+dp[i-1][j];
else if(j)dp[i][j]=b[i][j]+dp[i][j-1];
else dp[i][j]=b[i][j];
if(i)dp[i][j]=min(dp[i][j],b[i][j]+dp[i-1][j]);
if(j)dp[i][j]=min(dp[i][j],b[i][j]+dp[i][j-1]);
}
if(ans>dp[n-1][n-1]){
ans=dp[n-1][n-1];
road=""; dfs(n-1,n-1);
}
}
int main(){
scanf("%d",&n);
rep(i,n)rep(j,n)scanf("%d",&M[i][j]);
solve(2);solve(5);
rep(i,n)rep(j,n)if(M[i][j]==0&&ans>1){
ans=1;road="";
rep(k,i)road.push_back('D');
rep(k,j)road.push_back('R');
rep(k,n-i-1)road.push_back('D');
rep(k,n-j-1)road.push_back('R');
}cout<<ans<<endl<<road<<endl;
return 0;
}
C. Commentator problem
题目大意:给出三个圆(坐标,半径),求一个点,使得它与三个圆切线所形成的角相等,如果无法找到,则不输出
题解:首先将起点定位在三个点形成的三角形的重心,然后模拟退火,以1为起步长,不断重新调整选取点的位置,使得其最终符合要求。如果达到精度后无法满足,则不输出。
#include <cstdio>
#include <cmath>
using namespace std;
const double EPS=1e-6;
int d[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
struct C{double x,y,r;}c[3];
double dist(double x1,double y1,double x2,double y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
double f(double x,double y){
double u[3],ans=0;
for(int i=0;i<3;i++)u[i]=dist(x,y,c[i].x,c[i].y)/c[i].r;
for(int i=0;i<3;i++)ans+=(u[i]-u[(i+1)%3])*(u[i]-u[(i+1)%3]);
return ans;
}
int main(){
double x=0,y=0,step=2;
for(int i=0;i<3;i++){scanf("%lf%lf%lf",&c[i].x,&c[i].y,&c[i].r);x+=c[i].x/3;y+=c[i].y/3;}
while(step>EPS){
double tmp=f(x,y);
int flag=-1;
for(int i=0;i<4;i++){
double tmp1=f(x+d[i][0]*step,y+d[i][1]*step);
if(tmp1<tmp){tmp=tmp1;flag=i;}
}if(flag==-1)step/=2;
else{x=x+d[flag][0]*step;y=y+d[flag][1]*step;}
}if(f(x,y)<EPS)printf("%.5lf %.5lf\n",x,y);
return 0;
}
Codeforces Round#2的更多相关文章
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #370 - #379 (Div. 2)
题意: 思路: Codeforces Round #370(Solved: 4 out of 5) A - Memory and Crow 题意:有一个序列,然后对每一个进行ai = bi - bi ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #284 (Div. 2)A B C 模拟 数学
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...
随机推荐
- leetcode Merge K sorted Lists python
# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = ...
- Linux学习之/etc/init.d/functions详解
转自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=28773997&id=3996557 /etc/init.d/f ...
- CGI version1.1-第一章 介绍 (译)
CGI version1.1-第一章 介绍 1.简介 1.1 用途 CGI 是为 HTTP服务器 与 CGI脚本 在 响应客户端请求分配职责, 客户请求由url,方法与关于传输协议的附属信息, CGI ...
- 出现"无法连接synaptics定点装置驱动程序"
"开始“--”运行“--regedit(打开注册表)--依次打开 HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVERSION/R ...
- 图片延时加载jquery.inview.js用法详解
我们在网站上总能见到这样的效果,若是有图片,图片都是先用loading加载一小段时间,然后紧接着出来要显示的图片,即效果如下: v2_loading.gif,几秒钟时间过渡到v2_pic_01_s.j ...
- 【JQ成长笔记】jQuery Validate验证插件
validate是一款很好的jq插件,提供了强大的验证功能,让客户端表单验证变得更简单,同时提供了大量的定制选项,满足应用程序各种需求.该插件捆绑了一套有用的验证方法,包括 URL 和电子邮件验证,同 ...
- C#递归树
protected void Page_Load(object sender, EventArgs e) { bindtree(PopId); } private void bindtree() { ...
- .net mvc下的Areas和小写Url
首先是一个站点有前台后台两部分,这个要怎么来做.可以在mvc项目中添加区域(Areas)来实现,当添加一个名为Admin的区域时,项目下多了一个Areas/Admin目录,里边有Controllers ...
- eclipse 打开文件目录
用简单的配置方式 eclipse打开当前文件所在文件夹的插件 Run-->External Tools-->External Tools Configurations... new 一个 ...
- 深入Android媒体存储服务(二):磁盘扫描流程
简介: 本文是<深入Android媒体存储服务>系列第二篇,简要介绍媒体存储服务扫描文件的流程.文中介绍的是 Android 4.2. Android 有一套媒体存储服务,进程名是 and ...