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的更多相关文章

  1. 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 ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #370 - #379 (Div. 2)

    题意: 思路: Codeforces Round #370(Solved: 4 out of 5) A - Memory and Crow 题意:有一个序列,然后对每一个进行ai = bi - bi  ...

  9. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  10. 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 ...

随机推荐

  1. 【转】Pjax是什么以及为什么推荐大家用

    http://my.oschina.net/sub/blog/12344 技术增强的文章,可以看一下 .

  2. Linux 安装xtrabackup的依赖问题

    问题: 尝试安装xtrabackup rpm -ivh percona-xtrabackup-2.2.11-1.el7.x86_64.rpm 报错 perl(DBD::mysql) 被 percona ...

  3. Pthon MySQLdb 的安装

    说明: 要用python 去连接MySQL我们需要一个驱动程序这个程序就是MySQL-python,所以我们首先就是要下一个对应版本的MySQL-python (注意这个驱动程序只有32位版本的,所以 ...

  4. android中onStartActivityForResult无返回值问题

    在activity间跳转传递参数,常见方法是通过onStartActivityForResult来做.不过今天使用 onStartActivityForResult的时候已经在上一个activity调 ...

  5. wifi相关协议

    IEEE 802.11Wi-Fi 协议摘要 协议 频率 信号 最大,数据率 传统802.11 2.4GHz FHSS或DSSS 2Mbps 802.11a 5GHz OFDM 54Mbps 802.1 ...

  6. java学习之匿名内部类与包装类

    匿名内部类: 所谓匿名内部类,顾名思义指的就是定义在类内部的匿名类,现有的spring框架开发以及java图形界面都经常用到匿名内部类. 下面来看一个代码: interface A{ public v ...

  7. poj1833---字典序算法

    题意:给定一个序列,求它的下k个排列 #include <stdio.h> #include <stdlib.h> int cmp(const void *a,const vo ...

  8. gdb的user-define command

    搜索: user-defined例子. # save this file in ~/.gdb or some where easy to find. # then in ~/.gdbinit add ...

  9. uva 10003 Cutting Sticks (区间dp)

    本文出自   http://blog.csdn.net/shuangde800 题目链接:  打开 题目大意 一根长为l的木棍,上面有n个"切点",每个点的位置为c[i] 要按照一 ...

  10. html中文乱码

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">改成<m ...