A. Winner
time limit per test:1 second
memory limit per test:64 megabytes
input:standard input
output:standard output

The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to m) at the end of the game, than wins the one of them who scored at least m points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.

Input

The first line contains an integer number n (1  ≤  n  ≤  1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.

Output

Print the name of the winner.

Examples
Input
3 
mike 3
andrew 5
mike 2
Output
andrew
Input
3 
andrew 3
andrew 2
mike 5
Output
andrew

题目链接:http://codeforces.com/problemset/problem/2/A

题意:

给出一些列的名字和分数!正的表示加分,负的表示减分! 求最终分数最大的人的名字;

如果分数最大的人有多个,输出最先达到最大分数的人!

代码如下:

 #include <bits/stdc++.h>
using namespace std;
map<string, int> a,b;
string s[];
int main()
{
int x[];
int n;
cin >> n;
for(int i = ; i <= n; i++)
{
cin >> s[i] >> x[i];
a[s[i]]+=x[i];
}
int maxx = ;
for(int i = ; i <= n; i++)
{
if(a[s[i]] > maxx)
maxx = a[s[i]];
} for(int i = ; i <= n; i++)
{
b[s[i]]+=x[i];
if((b[s[i]]>=maxx) && (a[s[i]]>=maxx))//在最终分数是最大的人中,选首先达到最大分数的人
{
cout << s[i];
break;
}
}
return ;
}
B. The least round way
time limit per test:2 seconds
memory limit per test:64 megabytes
input:standard input
output:standard output

There is a square matrix n × n, consisting of non-negative integer numbers. You should find such a way on it that

  • starts in the upper left cell of the matrix;
  • each following cell is to the right or down from the current cell;
  • the way ends in the bottom right cell.

Moreover, if we multiply together all the numbers along the way, the result should be the least "round". In other words, it should end in the least possible number of zeros.

Input

The first line contains an integer number n (2 ≤ n ≤ 1000), n is the size of the matrix. Then follow n lines containing the matrix elements (non-negative integer numbers not exceeding 109).

Output

In the first line print the least number of trailing zeros. In the second line print the correspondent way itself.

Examples
Input
3 
1 2 3
4 5 6
7 8 9
Output
0 
DDRR

题目链接:http://codeforces.com/problemset/problem/2/B

题目大意

给定一个N*N的格子,每个格子里有一个非负数,要求你找出从左上角到右下角的一条路径,使得它满足路径上的格子里的数全部乘起来的积尾部0最少 题解

如果要产生0肯定是2*5得出来的,最终的乘积可以表示为2^x*5^y*C,那么零的个数就是min(x,y)。我们可以先对每个格子里的数预处理下,计算出2和5的个数来,然后DP分别求出2和5的最小个数然后选两者中的最小值,输出路径方法没啥说的,很传统~~还有一个要注意的问题就是如果某个格子的数字为0的情况,这个需要特殊判断一下,我们可以把它当做10,如果最后的结果0的个数大于1则直接输出尾部0的个数为1即可

下面给出AC代码:

 #include <bits/stdc++.h>
using namespace std;
#define MAXN 1005
#define INF 0x7fffffff
int path[MAXN][MAXN][];
int dp[MAXN][MAXN][],a[MAXN][MAXN][],n;
int zerox,zeroy,x;
string s;
bool flag;
int main()
{
scanf("%d",&n);
flag=false;
for(int i=;i<n;i++)
for(int j=;j<n;j++)
{
scanf("%d",&x);
if(!x)
{
a[i][j][]=a[i][j][]=;
zerox=i,zeroy=j,flag=true;
}
else
{
while(x%==) {a[i][j][]++;x/=;}
while(x%==) {a[i][j][]++,x/=;}
}
}
for(int k=;k<;k++)
for(int i=;i<n;i++)
for(int j=;j<n;j++)
{
int ans=INF;
if(i==&&j==) ans=;
if(i!=&&dp[i-][j][k]<ans) ans=dp[i-][j][k];
if(j!=&&dp[i][j-][k]<ans) ans=dp[i][j-][k],path[i][j][k]=;
dp[i][j][k]=ans+a[i][j][k];
}
int k=dp[n-][n-][]<dp[n-][n-][]?:;
if(flag&&dp[n-][n-][k]>)
{
for(int i=;i<zeroy;i++)
s+="R";
for(int i=;i<zerox;i++)
s+="D";
for(int i=;i<n-zeroy-;i++)
s+="R";
for(int i=;i<n-zerox-;i++)
s+="D";
cout<<<<endl<<s<<endl;
}
else
{
int i=n-,j=n-;
while(i>||j>)
{
if(path[i][j][k]==)
s+="R",j--;
else
s+="D",i--;
}
reverse(s.begin(),s.end());
cout<<dp[n-][n-][k]<<endl<<s<<endl;
}
return ;
}
C. Commentator problem
time limit per test:1 second
memory limit per test:64 megabytes
input:standard input
output:standard output

The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered.

Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.

Input

The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.

Output

Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.

Examples
Input
0 0 10 
60 0 10
30 30 10
Output
30.00000 0.00000

题目链接:http://codeforces.com/problemset/problem/2/C

题目大意:

有3个圆,求一点a,使点a对三个圆的视角相等(过a做圆的两条切线,此两切线的夹角即为视角)。若有多点视角相等,则取视角最大的点。

设三个圆的半径分别为r1,r2,r3。设点a到三个圆的圆心距离分别为d1,d2,d3。

即目标是2*arcsin(r1/d1) = 2*arcsin(r2/d2) = 2*arcsin(r3/d3)。即r1/d1 = r2/d2 = r3/d3

那么这就是解析几何的问题了,就是列出坐标系,一顿算呗。应该很难算。但是算出公式直接给程序就行了。

看到网上还有一种方法,就是一种随机的算法。

从一个初始的解开始逐步逼近最优解。

当迭代了若干步之后,估值函数的值仍然较大时,则不存在解。

最开始,我取的估值函数cost = fabs(ang1-ang2) + fabs(ang2-ang3) + fabs(ang3-ang1). 其中ang1 ang2 ang3就是用arcsin求出来的。

这样的问题就是可能会带来比较大的误差,因为要计算的arcsin的值可能很小,所以一开始一直都没法AC。

后来我把估值函数cost 取为cost = (d1/r1-d2/r2)^2 + (d2/r2-d3/r3)^2 + (d3/r3-d1/r1)^2,效果就好一些,就AC了。

总而言之呢,这种随机算法的题目就是很蛋疼了。但是在蛋疼的基础上,还是可以采取一些办法去减小误差的。

下面给出AC代码:

 #include <bits/stdc++.h>
using namespace std; struct pt {
double x;
double y;
double r;
}; pt mkp(double x, double y) {
pt ret;
ret.x = x;
ret.y = y;
return ret;
} double dis(pt a, pt b) {
return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
} double cost(pt *p, double x, double y) {
double ang[];
for (int i = ; i < ; i++) ang[i] = dis(p[i], mkp(x, y)) / p[i].r; double diff[];
for (int i = ; i < ; i++) diff[i] = ang[i] - ang[(i+)%]; double ret = ;
for (int i = ; i < ; i++) ret += diff[i] * diff[i]; return ret;
} const int dx[] = {, , -, };
const int dy[] = {, , , -};
const double err = 1e-;
int main() {
pt p[];
for (int i = ; i < ; i++) scanf("%lf %lf %lf", &(p[i].x), &(p[i].y), &(p[i].r)); pt ans;
ans.x = (p[].x + p[].x + p[].x) / 3.0;
ans.y = (p[].y + p[].y + p[].y) / 3.0;
double ncost = cost(p, ans.x, ans.y); pt tmp;
double step = 1.0;
bool flag = false;
for (int i = ; i < && ncost > err; i++) {
flag = false;
for (int k = ; k < ; k++) {
tmp.x = ans.x + step * ((double)dx[k]);
tmp.y = ans.y + step * ((double)dy[k]); if (ncost > cost(p, tmp.x, tmp.y)) {
ncost = cost(p, tmp.x, tmp.y);
ans = tmp;
flag = true;
}
}
if (!flag) step *= 0.5;
} if (cost(p, ans.x, ans.y) <= err) printf("%.5lf %.5lf\n", ans.x, ans.y);
return ;
}

Codeforces Beta Round #2 A,B,C的更多相关文章

  1. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  2. Codeforces Beta Round #62 题解【ABCD】

    Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...

  3. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  4. Codeforces Beta Round #13 C. Sequence (DP)

    题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...

  5. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  6. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  7. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  8. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

  9. Codeforces Beta Round #74 (Div. 2 Only)

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

  10. Codeforces Beta Round #73 (Div. 2 Only)

    Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...

随机推荐

  1. 图片Ping

    前面的话 在CORS出现以前,要实现跨域Ajax通信颇费一些周折.开发人员想出了一些办法,利用DOM中能够执行跨域清求的功能,在不依赖XHR对象的情况下也能发送某种请求.虽然CORS技术已经无处不在, ...

  2. 58、js扩展

    作用域是JavaScript最重要的概念之一,想要学好JavaScript就需要理解JavaScript作用域和作用域链的工作原理. 一.js的作用域 任何程序设计语言都有作用域的概念,简单的说,作用 ...

  3. 变量声明declare,简单运算符运算,变量测试与内容替换

    declare -/+ 选项 变量名 - 设类型 + 取消类型 -i 设为整型 -x 设为环境变量 -p 显示类型属性(property) [root@localhost ~]# a= [root@l ...

  4. Html中行内元素有哪些?块级元素有哪些?

    1.关于行内元素和块状元素的说明 根据CSS规范的规定,每一个网页元素都有一个display属性,用于确定该元素的类型,每一个元素都有默认的display属性值,比如div元素,它的默认display ...

  5. Parallels Desktop 12 for Mac 破解版

    Parallels Desktop for Mac 是功能最强大灵活度最高的虚拟化方案,无需重启即可在同一台电脑上随时访问Windows和Mac两个系统上的众多应用程序.从仅限于PC的游戏到生产力软件 ...

  6. Hive实际应用小结

    1.简介 Hive是数据仓库平台,构建在Hadoop之上用来处理结构化数据.Hive是一个SQL解析引擎,能够将SQL语句转化成MapReduce作业并在Hadoop上执行,从而使得查询和分析更加方便 ...

  7. [转]winform 自动伸缩控件xpandercontrols 使用说明

    链接地址:http://blog.sina.com.cn/s/blog_b5b004920101f5h3.html

  8. ArcGIS API for JavaScript 4.2学习笔记[9] 同一种视图不同数据(Map)同步

    本例子核心:对MapView对象的map属性值进行替换即可达到更改地图数据的效果. 这个例子用的不是Map对象了,而是用的发布在服务器上的专题地图(WebMap)来加载到MapView上进行显示. 在 ...

  9. parse_str 与 http_build_query的使用

    1 http_build_query() 使用 生成 URL-encode 之后的请求字符串 [建议在使用前,使用array_filter($query) 进行处理] 例子 1. http_build ...

  10. C# 判断网站是否能访问或者断链

    参考网站:http://www.cnblogs.com/junny/archive/2012/10/30/2745978.html public bool CheckUrlVisit(string u ...