Codeforces Beta Round#2

Codeforces Beta Round#2

http://codeforces.com/contest/2

A

模拟题

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4
 5 map<string,ll>mp;
 6 struct sair{
 7     string str;
 8     int id;
 9     ll num;
10 }a[1005];
11
12 bool cmp(sair a,sair b){
13     if(a.num==b.num) return a.id<b.id;
14     return a.num>b.num;
15 }
16
17 int main(){
18
19     int n;
20     cin>>n;
21     string ans;
22     ll Max=-0x3f3f3f3f;
23     for(int i=1;i<=n;i++){
24         cin>>a[i].str>>a[i].num;
25         a[i].id=i;
26     }
27     for(int i=1;i<=n;i++){
28         mp[a[i].str]+=a[i].num;
29         a[i].num=mp[a[i].str];
30     }
31     for(int i=1;i<=n;i++){
32         if(mp[a[i].str]>Max){
33             Max=mp[a[i].str];
34         }
35     }
36     sort(a+1,a+n+1,cmp);
37     map<string,ll>tmp;
38     for(int i=1;i<=n;i++){
39         if(mp[a[i].str]==Max){
40             tmp[a[i].str]=1;
41         }
42     }
43     int idmin=0x3f3f3f3f;
44     for(int i=1;i<=n;i++){
45         if(tmp[a[i].str]==1){
46             if(idmin>a[i].id&&a[i].num>=Max){
47                 idmin=a[i].id;
48                 ans=a[i].str;
49             }
50         }
51     }
52     cout<<ans<<endl;
53     //system("pause");
54
55 }

B

DP

能让末尾有0的情况是由2的倍数和5的倍数相乘,所以只要预处理出每个数中因子为2的个数和因子为5的个数,取最小值DP即可

  1 #include<bits/stdc++.h>
  2 using namespace std;
  3 #define lson l,mid,rt<<1
  4 #define rson mid+1,r,rt<<1|1
  5 typedef long long ll;
  6
  7 int n;
  8 int dp[1005][1005][2];///dp[i][j][0] 表示2的数量,dp[i][j][1] 表示5的数量
  9 int pre[1005][1005][2];
 10
 11 void print(int i,int j,int k,int flag){
 12     if(i==1&&j==1);
 13     else if(i==1) print(i,j-1,k,0);
 14     else if(j==1) print(i-1,j,k,1);
 15     else{
 16         if(dp[i][j][k]==dp[i][j-1][k]+pre[i][j][k])
 17             print(i,j-1,k,0);
 18         else
 19             print(i-1,j,k,1);
 20     }
 21     if(flag==2) return;
 22     cout<<(flag?"D":"R");
 23 }
 24
 25 int main(){
 26     #ifndef ONLINE_JUDGE
 27         freopen("1.txt","r",stdin);
 28     #endif
 29     std::ios::sync_with_stdio(false);
 30     cin>>n;
 31     int num,tmp;
 32     int x=-1,y=-1;
 33     memset(dp,0x3f,sizeof(dp));
 34     for(int i=1;i<=n;i++){
 35         for(int j=1;j<=n;j++){
 36             cin>>num;
 37             if(!num){
 38                 pre[i][j][0]++;
 39                 pre[i][j][1]++;
 40                 x=i,y=j;
 41                 continue;
 42             }
 43             tmp=num;
 44             while(tmp%2==0){
 45                 pre[i][j][0]++;
 46                 tmp/=2;
 47             }
 48             tmp=num;
 49             while(tmp%5==0){
 50                 pre[i][j][1]++;
 51                 tmp/=5;
 52             }
 53         }
 54     }
 55
 56     for(int i=1;i<=n;i++){
 57         for(int j=1;j<=n;j++){
 58             for(int k=0;k<2;k++){
 59                 if(i>1){
 60                     dp[i][j][k]=min(dp[i][j][k],dp[i-1][j][k]);
 61                 }
 62                 if(j>1){
 63                     dp[i][j][k]=min(dp[i][j][k],dp[i][j-1][k]);
 64                 }
 65                 if( i==1 && j==1 ){
 66                     dp[i][j][k]=0;
 67                 }
 68                 dp[i][j][k]+=pre[i][j][k];
 69             }
 70         }
 71     }
 72     int ans=min(dp[n][n][0],dp[n][n][1]);
 73     if(x!=-1&&y!=-1&&ans>=1){
 74         cout<<1<<endl;
 75         for(int i=1;i<x;i++){
 76             cout<<"D";
 77         }
 78         for(int i=1;i<y;i++){
 79             cout<<"R";
 80         }
 81         for(int i=x;i<n;i++){
 82             cout<<"D";
 83         }
 84         for(int i=y;i<n;i++){
 85             cout<<"R";
 86         }
 87         cout<<endl;
 88     }
 89     else{
 90         cout<<ans<<endl;
 91         if(dp[n][n][0]>dp[n][n][1]){
 92             print(n,n,1,2);
 93         }
 94         else{
 95             print(n,n,0,2);
 96         }
 97         cout<<endl;
 98     }
 99     return 0;
100 }

C

几何题+模拟退火

题意: 找一个点对每个圆切线的角度一样,如果有多个,就找角度最大的点

思路:asin(L/r)  只要L/r一样,它们的角度一定一样,所以用模拟退火枚举就好,感觉和2018icpc南京站的题很像

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define lson l,mid,rt<<1
 4 #define rson mid+1,r,rt<<1|1
 5 #define sqr(x) ((x)*(x))
 6 typedef long long ll;
 7
 8 struct circle{
 9     double x,y,r;
10 }c[5];
11
12 double angle[5];
13
14 double Check(double x,double y){
15     for(int i=0;i<3;i++){
16         angle[i]=sqrt(sqr(x-c[i].x)+sqr(y-c[i].y))/c[i].r;
17     }
18     double ans=0;
19     for(int i=0;i<3;i++){
20         ans+=sqr(angle[i]-angle[(i+1)%3]);
21     }
22     return ans;
23 }
24
25 int main(){
26     #ifndef ONLINE_JUDGE
27         freopen("1.txt","r",stdin);
28     #endif
29     for(int i=0;i<3;i++){
30         scanf("%lf %lf %lf",&c[i].x,&c[i].y,&c[i].r);
31     }
32     double ansx,ansy;
33     ansx=(c[0].x+c[1].x+c[2].x)/3;
34     ansy=(c[0].y+c[1].y+c[2].y)/3;
35     double step=1.0;
36     int flag;
37     double tmp;
38     while(step>1e-5){
39         flag=0;
40         tmp=Check(ansx,ansy);
41         if(tmp>Check(ansx+step,ansy)) ansx+=step,flag=1;
42         else if(tmp>Check(ansx-step,ansy)) ansx-=step,flag=1;
43         else if(tmp>Check(ansx,ansy+step)) ansy+=step,flag=1;
44         else if(tmp>Check(ansx,ansy-step)) ansy-=step,flag=1;
45         if(!flag) step*=0.8;
46     }
47     if(Check(ansx,ansy)<1e-5) printf("%.6f %.6f\n",ansx,ansy);
48
49 }

原文地址:https://www.cnblogs.com/Fighting-sh/p/10335911.html

时间: 2024-07-29 04:05:24

Codeforces Beta Round#2的相关文章

Codeforces Beta Round #91 (Div. 1 Only) E. Lucky Array

E. Lucky Array Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467are not. Petya has an arra

Codeforces Beta Round #85 (Div. 1 Only) C (状态压缩或是数学?)

C. Petya and Spiders Little Petya loves training spiders. Petya has a board n × m in size. Each cell of the board initially has a spider sitting on it. After one second Petya chooses a certain action for each spider, and all of them humbly perform it

CodeForces Beta Round #1

Codeforces Beta Round #1 A. Theatre Square [题意]一个n*m的矩形广场,用a*a的方形石板铺设,问最少需要多少块石板能铺满广场. [思路]水题,从n方向来看能能够铺设ceil(n/a)块,从m方向来看能能够铺设ceil(m/a)块,总共有ceil(n/a)*ceil(m/a)块. 1 /* 2 ** CodeForces 1A Theatre Square 3 ** Created by Rayn @@ 2014/05/18 4 */ 5 #inclu

暴力/DP Codeforces Beta Round #22 (Div. 2 Only) B. Bargaining Table

题目传送门 1 /* 2 题意:求最大矩形(全0)的面积 3 暴力/dp:每对一个0查看它左下的最大矩形面积,更新ans 4 注意:是字符串,没用空格,好事多磨,WA了多少次才发现:( 5 详细解释:http://www.cnblogs.com/cszlg/p/3217478.html 6 */ 7 #include <cstdio> 8 #include <algorithm> 9 #include <cstring> 10 #include <cmath>

Codeforces Beta Round #6 (Div. 2 Only) B. President&#39;s Office

题目大意 给出一个n*m的矩阵 ,描述桌子的布局.总统的桌子和他的副手的桌子相邻,每一个人的桌子有它独有的颜色.问总统有多少个副手. 解题思路 搜出总统的桌子在矩阵中的边界后判断边界外的其它颜色桌子的数量. 题目代码 #include <set> #include <map> #include <queue> #include <math.h> #include <vector> #include <string> #include

图论/暴力 Codeforces Beta Round #94 (Div. 2 Only) B. Students and Shoelaces

题目传送门 1 /* 2 图论/暴力:这是个连通的问题,每一次把所有度数为1的砍掉,把连接的点再砍掉,总之很神奇,不懂:) 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <algorithm> 7 #include <cmath> 8 using namespace std; 9 10 const int MAXN = 1e2 + 10; 11 const int INF = 0x3f3f3

Codeforces Beta Round #1 B. Spreadsheets

Codeblocks坏掉了,我不知道该怎么修,只能过两天重装系统了. 没办法.这个题是用Java写的,代码风格不好不要骂我~~ 题目大意: Excel表格那种坐标系统,和正常的坐标系统.用代码实现转换. 就是模拟题啊,代码量比较小. 下面是代码: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); i

Codeforces Beta Round #1 C. Ancient Berland Circus

果然Java还是不靠谱啊,一个NaN把我整了半天~~ 题目大意: 有一个正多边形,给出任意三个顶点的坐标,求这个正多边形的最小面积. 解题思路: 首先要知道这三个顶点组成的三角形的外接圆一定是这个正多边形的外接圆. 用过计算出三角形的三边长,可以计算出三角型面积,进而推出外接圆半径. 可以得到三个圆心角,找出最大公约数,那就是最大角度. 就可以计算出多边形面积了~~ 下面是代码: import java.text.DecimalFormat; import java.util.Scanner;

codeforces Beta Round #19 D. Point (线段树 + set)

题目大意: 对平面上的点进行操作. add x y 在 (x,y )上加一个点. remove x y 移除 (x,y)上的点. find x y 求出在(x,y)右上角离他最近的点,优先级是靠左,靠下. 思路分析: find 操作 比较麻烦. 要保证x大的同时还要确保x最小,而且该x上还要有点. 这样要找大的时候要小的,就是在线段树上选择性的进入左子树还是右子树. 所以核心就是,用set维护叶子节点. 然后查找的时候去叶子节点找,如果这个叶子节点有蛮子的 x y  就输出,否则回溯去另外一个子