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 Swap Nodes in Pairs python
# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = ...
- 各种数据库的批量插入操作_Oracle
最近工作中需要优化以前各种的Excel批量导入功能,目前将能优化的方面做个记录. 选用技术: 目前.Net可以访问Oracle常用的Dll,有三种: 微软自带的 System.Data.OracleC ...
- JQuery easyui (3) Resizable(调整大小)组件
Resizable 动态调整元素大小 不依赖其他组件 Resizable的加载方法 <div class="easyui-resizable"></div&g ...
- Centos for php+mysql+apache
一.安装 MySQL 首先来进行 MySQL 的安装.打开超级终端,输入: [root@localhost ~]# yum install mysql mysql-server 安装完毕,让 MySQ ...
- 修改host文件的P处理
notepad C:\WINDOWS\system32\drivers\etc\hosts 用文档创建hosts文件,添加上面代码.把文件后缀修改为 .bat 就不用每次很麻烦的查找host文件了.
- Generative Learning algorithms
"generative algorithm models how the data was generated in order to categorize a signal. It ask ...
- boa,thttp服务器安装,配置,测试
boa 1, SERVER_ROOT自定义,define.h头文件中,默认“/etc/boa" 2,./configure 3,修改CC,默认CC=gcc,make 4,error util ...
- Exchange Web Service 获取邮件的附件并保存到本地的示例代码
private static void DownLoadMailAttachments(ExchangeService service, ItemId itemId) { EmailMessage m ...
- wpf中的触发器详解
原文 http://zwkufo.blog.163.com/blog/static/25882512009724113250883/ 7.1.2 简单逻辑的表示--触发器(1) 在本章的多处介绍中都会 ...
- Android自定义Activity酷炫的动画跳转效果
两个Activity跳转的时候,自定义翻页效果: Intent intent = new Intent(FirstActivity.this, SecondActivity.class); sta ...