Codeforces Beta Round #2 A map B dp C 模拟退火




链接:戳这里


A. Winner
time limit per test1 second
memory limit per test64 megabytes
inputstandard input
outputstandard 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


题意:

给出n个名字和得分  输出得分最多的人的名字  如果得分一样 输出靠前的人名字


思路:

map存 然后模拟


代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<iomanip>
#include<cmath>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define maxn 0x3f3f3f3f
#define MAX 1000100
///#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef unsigned long long ull;
#define INF (1ll<<60)-1
using namespace std;
map<string,int >mp,g;
int n;
string s[1010];
int x[1010];
int main(){
    scanf("%d",&n);
    string ans;
    for(int i=1;i<=n;i++){
        cin>>s[i]>>x[i];
        mp[s[i]]+=x[i];
    }
    int m=0;
    for(int i=1;i<=n;i++){
        if(mp[s[i]]>m) m=mp[s[i]];
    }
    int t=1;
    while(mp[s[t]]<m || (g[s[t]]+=x[t])<m){
        t++;
    }
    cout<<s[t]<<endl;

    return 0;
}



B. The least round way
time limit per test5 seconds
memory limit per test64 megabytes
inputstandard input
outputstandard 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


题意:

给出n*n的矩阵,要求从(1,1)->(n,n)  所走的路径的值相乘的总乘积的末尾0的个数最少


思路:

末尾能够产生0  只可能是由2*5得到

所以先求出dp[1][1]->dp[i][j]的路径上2|5的个数  尽量要求2或者5少才可能是最优解

dp[i][j][k]  k=0为末尾为2的个数  k=1则是末尾为5的个数

dp[i][j][k]=min(dp[i-1][j][k],dp[i][j-1][k])+cnt[i][j][k]   cnt[i][j][k]为i,j位置上2|5的个数

然后取出2|5最少的路径  从dp[n][n][k]返回dp[1][1][k]


代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<iomanip>
#include<cmath>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define maxn 0x3f3f3f3f
#define MAX 1000100
///#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef unsigned long long ull;
#define INF (1ll<<60)-1
using namespace std;
int dp[1010][1010][2];
int n;
int main(){
    scanf("%d",&n);
    int tmp=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            int x;
            scanf("%d",&x);
            if(x==0) {
                tmp=i;
                continue;
            }
            while(x%2==0) {
                dp[i][j][0]++;
                x/=2;
            }
            while(x%5==0) {
                dp[i][j][1]++;
                x/=5;
            }
        }
    }
    for(int i=2;i<=n;i++){
        dp[i][1][0]+=dp[i-1][1][0];
        dp[1][i][0]+=dp[1][i-1][0];
        dp[i][1][1]+=dp[i-1][1][1];
        dp[1][i][1]+=dp[1][i-1][1];
    }
    for(int i=2;i<=n;i++){
        for(int j=2;j<=n;j++){
            dp[i][j][0]+=min(dp[i-1][j][0],dp[i][j-1][0]);
            dp[i][j][1]+=min(dp[i-1][j][1],dp[i][j-1][1]);
        }
    }
    /*cout<<endl;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            printf("%d ",dp[i][j][0]);
        }
        cout<<endl;
    }
    cout<<endl;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            printf("%d ",dp[i][j][1]);
        }
        cout<<endl;
    }*/
    int k=0;
    if(dp[n][n][1]<dp[n][n][0]) k=1;
    if(tmp>0 && dp[n][n][k]>0){
        printf("1\n");
        for(int i=1;i<tmp;i++) cout<<"D";
        for(int i=1;i<n;i++) cout<<"R";
        for(int i=tmp;i<n;i++) cout<<"D";
        cout<<endl;
        return 0;
    }
    string ans;
    int i=n,j=n;
    while(i>0 && j>0){
        if(i==1 && j==1) break;
        if(i==1) {
            ans+="R";
            j--;
            continue;
        }
        if(j==1) {
            ans+="D";
            i--;
            continue;
        }
        if(dp[i-1][j][k]<dp[i][j-1][k]){
            ans+="D";
            i--;
        } else {
            ans+="R";
            j--;
        }
    }
    printf("%d\n",dp[n][n][k]);
    for(int i=ans.size()-1;i>=0;i--) cout<<ans[i];
    cout<<endl;
    return 0;
}
/*
3
4 10 5
10 9 4
6 5 3
5
8 3 2 1 4
3 7 2 4 8
9 2 8 9 10
2 3 6 10 1
8 2 2 8 4
*/


C. Commentator problem
time limit per test1 second
memory limit per test64 megabytes
inputstandard input
outputstandard 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


题意:

给出3个互不相交且圆心不共线的圆  求一个同时在三个圆外的点,使得这个点对三个圆的视角相同,多解输出视角最大的点


思路:

反正模拟退火这种东西即使你A了你也会不爽的   没有解方程来的爽快啊  可是我解不出


代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<iomanip>
#include<cmath>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define maxn 0x3f3f3f3f
#define MAX 1000100
///#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef unsigned long long ull;
#define INF (1ll<<60)-1
using namespace std;
double x[5],y[5],r[5],ang[5];
const double eps=1e-5;
double disn(double x1,double y1,double x2,double y2){
    return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}
double F(double X,double Y){
    double sum=0.0;
    for(int i=0;i<3;i++) {
        ang[i]=disn(x[i],y[i],X,Y)/r[i];
        sum+=ang[i];
    }
    sum/=3.0;
    double deta=0.0;
    for(int i=0;i<3;i++){
        deta+=(ang[i]-sum)*(ang[i]-sum);
    }
    return deta;
}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    double X=0.0,Y=0.0;
    for(int i=0;i<3;i++) {
        scanf("%lf%lf%lf",&x[i],&y[i],&r[i]);
        X+=x[i];
        Y+=y[i];
    }
    X/=3.0;Y/=3.0;
    double t=1.0;
    while(t>eps){
        double ans=F(X,Y),xx,yy;
        int i;
        for(i=0;i<4;i++){
            xx=X+dx[i]*t;
            yy=Y+dy[i]*t;
            if(F(xx,yy)<ans) break;
        }
        if(i==4) t*=0.82;
        else {
            X=xx;
            Y=yy;
        }
    }
    if(fabs(F(X,Y))<eps) printf("%.5f %.5f\n",X,Y);
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值