Codeforces Beta Round #2

2023-05-16

codeforces 2A.Winner

codeforces 2B.The least round way

codeforces 2C.Commentator problem

这期题目想对感觉较难 A敲了十多分钟 B是想了很久才开始写的中间TLE无数次 C完全懵逼 不过最后发现用爬山算法?/模拟退火可以求解 拖了好几天今天终于把C好好的敲了一下 现在送上题解

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/contest/2/problem/A

题解:输入选手姓名和分数 求最后得分最高的人 然后注意是分数最高可能很多人取第一个达到这个分数的人 然后分数可能负数 

思路比较清晰 map简单应用 第一次循环求出所有人的最后得分 然后最后得分中取出得分最高的人 最后重新判定一下谁先得到这个分数

AC代码:

#include <bits/stdc++.h>
using namespace std;
map<string, int> mp, m;
vector<string> vec;
vector<int> ve;
int ma = -0xffffff;
string winer;

int main() {
    string str;
    int score;
    int n;
    cin >> n;
    getchar();
    for(int i = 0; i <n; ++i) {
        cin >> str >> score;
        mp[str] += score;
        vec.push_back(str);
        ve.push_back(score);
    }

    map<string, int>::iterator it;
    for(it = mp.begin(); it != mp.end(); ++it) {
        ma = max(it->second, ma);
    }

    for(int i = 0; i < n; ++i) {
        m[vec[i]] += ve[i];
        if(m[vec[i]] >= ma && mp[vec[i]] == ma) {
            cout << vec[i] << endl;
            break;
        }
    }

    return 0;
}

B. The least round way
time limit per test
5 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/contest/2/problem/B

题解:从左上角到右下角经过的数字的乘积最后至少有几个0

dp 一个记录经过当前点最少的约数2的数目 一个记录经过当前点最少的约数5的数目 然后取抵达最后一个点2和5的数目最少的那个 TLE无数次 然后其实只是因为一个0的判断未跳出

AC代码:

#include <bits/stdc++.h>
using namespace std;
const int inf = 0xffffff;
const int maxn = 1010;
int dp[maxn][maxn][2];      //记录得到当前点最少的2和5的数目
int dir[maxn][maxn][2];     //方向
int num[maxn][maxn][2];     //当前点2和5的数目
int n;
bool mark;
int cnt;

void print(int x, int y, int k);

int main() {
    scanf("%d", &n);
    memset(num, 0, sizeof(num));        //初始化
    memset(dir, 0, sizeof(dir));        //初始化
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            int tmp;
            scanf("%d", &tmp);
            dp[i][j][0] = inf;
            dp[i][j][1] = inf;
            if(tmp == 0) {
                mark = true;
                cnt = i;
                continue;
            }
            while(tmp % 2 == 0) {
                ++ num[i][j][0];
                tmp /= 2;
            }
            while(tmp % 5 == 0) {
                ++ num[i][j][1];
                tmp /= 5;
            }
        }
    }
    dp[0][0][0] = num[0][0][0];
    dp[0][0][1] = num[0][0][1];
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            if(i) {
                if(dp[i][j][0] > dp[i-1][j][0] + num[i][j][0]) {
                    dp[i][j][0] = dp[i-1][j][0] + num[i][j][0];
                    dir[i][j][0] = 0;
                }
                if(dp[i][j][1] > dp[i-1][j][1] + num[i][j][1]) {
                    dp[i][j][1] = dp[i-1][j][1] + num[i][j][1];
                    dir[i][j][1] = 0;
                }
            }
            if(j) {
                if(dp[i][j][0] > dp[i][j-1][0] + num[i][j][0]) {
                    dp[i][j][0] = dp[i][j-1][0] + num[i][j][0];
                    dir[i][j][0] = 1;
                }
                if(dp[i][j][1] > dp[i][j-1][1] + num[i][j][1]) {
                    dp[i][j][1] = dp[i][j-1][1] + num[i][j][1];
                    dir[i][j][1] = 1;
                }
            }
        }
    }
    int k = dp[n-1][n-1][0] > dp[n-1][n-1][1] ? 1 : 0;
    if(mark && dp[n-1][n-1][k] > 1) {
        puts("1");
        for(int i = 1; i <= cnt; ++i) {
            printf("D");
        }
        for(int i = 1; i < n; ++i) {
            printf("R");
        }
        for(int i = cnt+1; i < n; ++i) {
            printf("D");
        }
        puts("");
    }
    else {
        printf("%d\n", dp[n-1][n-1][k]);
        print(n-1, n-1, k);
        puts("");
    }

    return 0;
}

void print(int x, int y, int k) {           //递归输出
    if(x == y && y == 0) {
        return ;
    }
    if(dir[x][y][k] == 0) {
        print(x-1, y, k);
        printf("D");
    }
    else if(dir[x][y][k] == 1) {
        print(x, y-1, k);
        printf("R");
    }
}

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/contest/2/problem/C

题解:三个圆 不相交 然后求一个点到三个点的视角和最大

模拟退火算法 这里用到一个小技巧就是估价函数视角的和的选取 用距离/半径 然后视角和用距离/半径的差的平方的和来代替 精度到一定范围就可以得出答案 这道题是随机算法求解的所以一定注意精度

PS:这道题拖了好久一直不想碰 因为觉得模拟退火理解的不够 好吧其实就是这几天比较懒 

AC代码:

#include <bits/stdc++.h>
using namespace std;
struct Circle {
    double x, y, r;
};
const int dy[4] = {-1, 0, 0, 1};
const int dx[4] = {0, -1, 1, 0};
double ang[3];
Circle c[3];
double K(double x) {
    return x * x;
}

double Dis(double x, double y, double xx, double yy) {
    return sqrt(K(x - xx) + K(y - yy));
}

double Val(double x, double y) {            //估价函数
    for(int i = 0; i < 3; ++i) {
        ang[i] = Dis(x, y, c[i].x, c[i].y) / c[i].r;
    }
    double val = 0;
    for(int i = 0; i < 3; ++i) {
        val += K(ang[i] - ang[(i+1) % 3]);
    }
    return val;
}

int main() {
    double x = 0, y = 0;
    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;
    }

    //模拟退火
    double err = Val(x, y);
    double step = 1;
    for(int tim = 1; tim < 1e5; ++tim) {
        bool flag = false;
        double X, Y;
        for(int i = 0; i < 4; ++i) {
            double xx = x + dx[i] * step;
            double yy = y + dy[i] * step;
            double val = Val(xx, yy);
            if(val < err) {
                err = val;
                flag = true;
                X = xx;
                Y = yy;
            }
        }
        if(flag) {
            x = X;
            y = Y;
        }
        else {
            step /= 2;
        }
    }

    if(err < 1e-6) {
        printf("%.5f %.5f\n", x, y);
    }
    return 0;
}




本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Codeforces Beta Round #2 的相关文章

  • 1500*C. Tenzing and Balls (线性DP)

    解析 每次选择两个相同的数 删去他们以及他们之间的所有数 问最多可以删除多少 DP 对于某个位置 i 其前面有多个 j 使得 a i a j 所以使用 f i 来记录前 i 个数能够删除的最大值 include
  • Catowice City【Codeforces 1248 F】【Tarjan】

    Codeforces Round 594 Div 2 F 这道题的解法还真是不少 写了个枚举也可以做这道题 当然Tarjan自然也是可以的 我一开始没捋清楚思路 再想想 发现 我们看到审判者 他们都会指向一些参赛选手 那么我们是不是可以尽力
  • Codeforces Round #328 (Div. 2)(A B C D)

    Codeforces Round 328 Div 2 tags Codeforces 难得题目不难 结果比赛的时候C题差一分钟没交上去 不然怎么着都能涨个百来分啊 T T Codeforces Round 328 Div 2 A PawnC
  • Codeforces Round #808 (Div. 2)C - Doremy‘s IQ

    C Doremy s IQ time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output D
  • 动态动态规划(DDP)

    1 Problem E Codeforces 一 题目大意 给你一个无向图 第i和i 1条边的权值是w i 问你每个点不在自己原本的点的代价是多少 会有q组询问 表示修改第i条边的权值 二 解题思路 可以观察到 完成这个操作需要每条边经过两
  • Voting【Codeforces 1251 E1 && E2】【贪心】

    Educational Codeforces Round 75 Rated for Div 2 E2 Now elections are held in Berland and you want to win them More preci
  • Codeforces Round 739 (Div. 3)

    A Dislike of Threes AC代码 include
  • Codeforces Round #561 (Div. 2)ABC

    三个题 各位大佬别喷我 我很菜 A Silent Classroom There are n students in the first grade of Nlogonia high school The principal wishes
  • Codeforces 1454B Unique Bid Auction(模拟)

    Description 题目大意 找到一个序列中唯一且是最小的那个数的下标 感叹我的语言描述真是越来越精炼了 解题思路 算法标签 模拟 记录每个数字出现的次数以及其下标 然后从1开始寻找 第一个找到的数字的下标就是答案 没什么难度 只是不想
  • 1600*D. Road Map(数学

    解析 记录每个点的父节点和子节点 从新的根节点开始遍历 遍历所有的非父结点即可 include
  • Swift 3 中的 NSNotifications

    新通知目前在 Swift 3 中不起作用吗 我在做 NotificationCenter default post name DidTouchParticleView object self particle as AnyObject 在自
  • Xcode 6 / Beta 4:不支持将桥接标头与框架目标一起使用

    我刚刚升级到 Xcode 6 Beta 4 并拥有一个为 Beta 2 中的实时视图创建的框架 由于另一个 swiftbug 我需要使用一些 Obj C 代码 但升级时 我收到以下错误 错误 不支持将桥接标头与框架目标一起使用 我没有在发行
  • ARKit 2 冻结:是 bug 还是我的不幸?

    只有我在 iOS 12 上的 ARKit 中经历了整个场景冻结的情况吗 当您在生成过于密集的点云的空间中使用该应用程序太长时间时 通常会发生这种情况 经过一定时间后 整个图片开始滞后 然后完全停止移动 直到您遮盖相机 或将其远离物体 或重置
  • Codeforces Round 915 (Div. 2) A-F(补题&补写法)

    A Constructive Problems 签到 题解 输出max x y t int input for in range t u v map int input split print max u v B Begginer s Ze
  • beta 二项式和 beta 分布的 alpha 和 beta 估计

    我正在尝试将我的数据拟合到 beta 二项式分布并估计 alpha 和 beta 形状参数 对于此分布 先验取自 beta 分布 Python 没有 beta 二项式的拟合函数 但有 beta python beta 拟合和 R beta
  • Microsoft Graph:使用测试版获取用户日历事件

    我正在尝试使用 Microsoft Graph beta 版本获取用户日历事件 我可以通过此请求获取日历信息 https graph microsoft com beta users user calendars calendarid 然后
  • chol.default(K) 中出现错误:5 阶前导小数对于 betareg 不是正定的

    我正在尝试适应一个beta regression模型使用betareg function of the betareg package对这些数据 df lt data frame category c c1 c1 c1 c1 c1 c1 c
  • 4 年每日数据的滚动回归,每个新回归和不同因变量提前一个月

    我有 5 个自变量 附加数据中的 B F 列 和一些因变量 附加数据中的 G M 列 我需要针对所有自变量对每个因变量进行多重回归 回归必须有 4 年的数据窗口 并且每个新的估计都必须提前一个月 我需要提取系数并对每个系数进行 vasice
  • Xcode Beta3 中的 CMutablePointer 和 CConstPointer 发生了什么?

    Xcode Beta3 中的 CMutablePointer 和 CConstPointer 发生了什么 在 Beta2 中成功编译的代码失败并出现错误 Use of undeclared type CMutablePointer 分别使用
  • Google Play 中的生产版和测试版

    我已在 Google Play 中以生产模式发布了一个应用程序 现在 我有一个新版本 我想以 Beta 模式为有限数量的私人 Beta 用户发布 有可能两者兼得吗 即生产模式下的版本 1 0 和测试模式下的版本 1 1 或者我应该维护一个不

随机推荐

  • 原版win7全新安装后无法通过windows update安装更新的解决办法.2023-03-07

    首先要确保网络畅通 系统时间设置正确 系统没有被病毒流氓程序等破坏 是一个正常完整的初始安装的系统 方法一 1 安装 Windows 更新客户端 kb3138612 kb3138612 Microsoft Update Catalog 2
  • xmind 8 pro Mac破解版(思维导图) 附xmind 8 序列号

    链接 https pan baidu com s 1tTKYuqCjGo WC2ns6tN54w 密码 1b1w 转载地址 小伙伴们XMind 8 pro Mac破解版 思维导图 最新版本v3 7 8中文破解版上线了 xff0c 本次的XM
  • 操作系统系列笔记(五) - 同步互斥, 信号量和管程

    同步互斥 背景 并发进程在多个进程间有资源共享 导致执行过程是不确定性和不可重现的 程序错误可能是间歇性发生 原子操作 是指一次不存在任何中断或失败的操作 操作系统需要利用同步机制 在并发执行的同时保证一些操作是原子操作 几个状态 互斥 一
  • compilation terminated. The terminal process terminated with exit code: 1头文件包含错误解决办法

    错误描述 xff1a d coding clanguage datastruct chapterone mian1 cpp 1 46 fatal error c1 h No such file or directory include 34
  • 实践支持HTTPS SSL的七牛云存储CDN

    最近 xff0c 听说七牛云存储CDN这货支持HTTPS SSL Godaddy SSL证书 xff0c 试用了一下 xff0c 简直发现了新大陆 刚开始设置好以后 xff0c 发现HTTPS下的网页并没有采用七牛的服务 xff0c 只是H
  • 超详细,多图,PVE安装以及简单设置教程(个人记录)

    前言 写这个的目的是因为本人健忘所以做个记录以便日后再折腾时查阅 本人笔拙如有选词 xff0c 错字 xff0c 语法 xff0c 标点错误请忽视 xff0c 大概率知道了也不会修改 xff0c 本人能看懂就好 内容仅适用于本人的使用环境
  • Visual Studio 编译时moc 某些头文件找不到,编译不过,解决办法

    Visual Studio 编译时moc 某些头文件找不到 xff0c 编译不过 xff0c 解决办法 主要是不同的VS版本提交时存在的差异造成的 需要把编译时moc不过的头文件先移除掉 xff0c 然后再添加回来 xff0c 再编译就能编
  • UITableViewController使用

    列表视图控制器 xff0c 用起来很方便 xff0c 不仅可以实现分组列表 xff0c 连tem都有很多定义好的样式 xff0c 使用时基本上不需要有大的自定义的部分 xff0c 这里做一些简单的尝试 1 新建MyTableViewCont
  • TQ2440外接GPIO蜂鸣器驱动程序

    本文通过TQ2440开发板上可外接的GPIO口GPG14连接蜂鸣器 xff0c 通过控制GPG14引脚的高低电平的输出和高低电平输出之间的时间间隔来使蜂鸣器发出不同的声音 1 打开S3C2440的底板原理图找到GPIO xff0c 如下图所
  • Ubuntu下QT静态编译教程

    1 安装Ubuntu系统 xff0c 然后 root 账户登录 xff0c 不然可能会有权限问题 xff0c 避免麻烦 2 打开终端 xff0c 安装必要环境 xff1a 注 xff1a 如安装时 xff0c 遇到暂停需要输入y时 xff0
  • 用 GitHub Actions 自动打包发布 Python 项目

    用 GitHub Actions 自动打包发布 Python 项目 文章目录 用 GitHub Actions 自动打包发布 Python 项目前言在 GitHub 上保存 token创建 workflow定义工作流程的工作环境签出项目 x
  • 用 R 做数据分析

    用 R 做数据分析 Vol 0 xff1a 数据的数字特征及相关分析 导入数据 导入文本表格数据 Year Nationwide Rural Urban 1978 184 138 405 1979 207 158 434 1980 236
  • win下配置Rust及Clion开发环境

    登录官网下载最新的win安装包 地址 默认情况下 rustup安装在用户目录下 也就是C盘 这里我们通过修改环境变量的方式 安装到D盘 RUSTUP HOME 存储工具链和配置文件CARGO HOME 存储cargo的缓存 一定要在rust
  • [docker]CentOS安装docker

    文章目录 先卸载旧版本添加 Docker 软件源使用dnf安装使用yun安装 配置镜像源加速关于tencentOS系统的差异处理 先卸载旧版本 span class token function sudo span yum remove s
  • c语言printf输出格式

    最近C语言中遇到一些基础知识 xff0c 写出来分享一下 xff1a 一 一些基本输出格式小试 include lt stdio h gt include lt stdlib h gt int main int x 61 017 print
  • Linux man命令解析

    文章目录 使用方法手册页面结构手册章节说明命令选项命令参数常见用法1 man k command2 man f command man命令 英文单词manual 使用手册 的缩写 是Linux系统中的一个命令 用于显示其他命令的手册页面 它
  • Linux usr/share/doc帮助文档介绍

    文章目录 usr share doc介绍目录结构查看文档使用文档总结附录 xff1a 关于删除 usr share doc的影响 usr share doc 介绍 在Linux系统中 usr share doc目录是非常重要的 它是用来存储
  • POJ题目分类 很好很有层次感

    OJ上的一些水题 可用来练手和增加自信 poj3299 poj2159 poj2739 poj1083 poj2262 poj1503 poj3006 poj2255 poj3094 初期 一 基本算法 1 枚举 poj1753 poj29
  • Codeforces Beta Round #1

    做了好久 感觉做的有点蠢 题目总体难度不高吧应该 因为考虑的不周WA了两次 题目传送门 xff1a http codeforces com contest 1 A Theatre Square time limit per test 1 s
  • Codeforces Beta Round #2

    codeforces 2A Winner codeforces 2B The least round way codeforces 2C Commentator problem 这期题目想对感觉较难 A敲了十多分钟 B是想了很久才开始写的中