1、前言

虽然这次我依旧没有参加正式比赛,但是事后还是看了看题目的。。。一般不怎么刷Codeforces。

A、Raising Bacteria

You are a lover of bacteria. You want to raise some bacteria in a box.

Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment.

What is the minimum number of bacteria you need to put into the box across those days?

 
>Input

The only line containing one integer x (1 ≤ x ≤ 109).

 
>Output

The only line containing one integer: the answer.

>Sample test(s)
 
input
5
output
2
 
input
8
output
1
 
>Note

For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.

For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1.

题解:找出所给数中包含多少个2^k(k∈[1,30])即可。

-------------------------------------------------------------------------------------------

#include<cstdio>

int n,tot;

int main()
{
  scanf("%d",&n);
  for (int i=1<<30;i>=1;i>>=1) if (n>=i) n-=i,tot++;
  printf("%d",tot);
  return 0;
}

-------------------------------------------------------------------------------------------

B、Finding Team Member

There is a programing contest named SnakeUp, 2n people want to compete for it. In order to attend this contest, people need to form teams of exactly two people. You are given the strength of each possible combination of two people. All the values of the strengths aredistinct.

Every contestant hopes that he can find a teammate so that their team’s strength is as high as possible. That is, a contestant will form a team with highest strength possible by choosing a teammate from ones who are willing to be a teammate with him/her. More formally, two people A and B may form a team if each of them is the best possible teammate (among the contestants that remain unpaired) for the other one.

Can you determine who will be each person’s teammate?

 
>Input

There are 2n lines in the input.

The first line contains an integer n (1 ≤ n ≤ 400) — the number of teams to be formed.

The i-th line (i > 1) contains i - 1 numbers ai1, ai2, ... , ai(i - 1). Here aij (1 ≤ aij ≤ 106, all aij are distinct) denotes the strength of a team consisting of person i and person j (people are numbered starting from 1.)

 
>Output

Output a line containing 2n numbers. The i-th number should represent the number of teammate of i-th person.

>Sample test(s)
input
2
6
1 2
3 4 5
output
2 1 4 3
input
3
487060
3831 161856
845957 794650 976977
83847 50566 691206 498447
698377 156232 59015 382455 626960
output
6 5 4 3 2 1
>Note

In the first sample, contestant 1 and 2 will be teammates and so do contestant 3 and 4, so the teammate of contestant 1, 2, 3, 4 will be2, 1, 4, 3 respectively.

题解:求得所有对的默契值,从大到小排序,然后一一配对,如果已经配对过则跳过。

-------------------------------------------------------------------------------------------

#include<cstdio>
#include<algorithm>
#define MAXN 320005
using namespace std;

struct Num
{
  int val,x,y;
};
Num a[MAXN];

struct Cmp
{
  bool operator () (Num a,Num b)
  {
    return (a.val>b.val);
  }
};
Cmp x;

int n,tot,ans[810];

int main()
{
  scanf("%d",&n);
  for (int i=2;i<=2*n;i++)
  for (int j=1;j<=i-1;j++) scanf("%d",&a[++tot].val),a[tot].x=i,a[tot].y=j;
  sort(a+1,a+tot+1,x);
  for (int i=1;i<=tot;i++)
  {
    if (ans[a[i].x] || ans[a[i].y]) continue;
    ans[a[i].x]=a[i].y,ans[a[i].y]=a[i].x;
  }
  for (int i=1;i<=2*n;i++) printf("%d ",ans[i]);
  return 0;
}

-------------------------------------------------------------------------------------------

C. A Problem about Polyline
 
There is a polyline going through points (0, 0) – (x, x) – (2x, 0) – (3x, x) – (4x, 0) – ... - (2kx, 0) – (2kx + x, x) – ....

We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or determine that there is no such x.

>Input

Only one line containing two positive integers a and b (1 ≤ a, b ≤ 109).

 
>Output

Output the only line containing the answer. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9. If there is no such x then output  - 1 as the answer.

 
>Sample test(s)
input
3 1
output
1.000000000000
input
1 3
output
-1
input
4 1
output
1.250000000000
>Note

You can see following graphs for sample 1 and sample 3.

题解:首先可以确定的是,该函数由y=x延伸而来。因为点在直线上,显然b<a无解;否则分为两种情况,一种是点(a,b)在斜率为1的线上,那么这个线段过(a-b,0)这个点,同理如果在斜率为-1的线上,那么这个线段过(a+b,0)这个点。

-------------------------------------------------------------------------------------------

#include <cstdio>

int a,b;

int main()
{
  scanf("%d %d",&a,&b);
  if (a<b) printf("-1");
  else printf("%.12f\n",(a+b)/(2.0*((a+b)/(2*b))));
  return 0;
}

-------------------------------------------------------------------------------------------

[Codeforces] Round #320 (Div.2)的更多相关文章

  1. Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] C. Weakness and Poorness 三分 dp

    C. Weakness and Poorness Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  2. Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] B. "Or" Game 线段树贪心

    B. "Or" Game Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/578 ...

  3. Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] B. "Or" Game

    题目链接:http://codeforces.com/contest/578/problem/B 题目大意:现在有n个数,你可以对其进行k此操作,每次操作可以选择其中的任意一个数对其进行乘以x的操作. ...

  4. codeforces Round #320 (Div. 2) C. A Problem about Polyline(数学) D. "Or" Game(暴力,数学)

    解题思路:就是求数 n 对应的二进制数中有多少个 1 #include <iostream> #include<cstdio> using namespace std; int ...

  5. Codeforces Round #320 (Div. 2) D. "Or" Game 数学

    D. "Or" Game time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  6. codeforces 578a//A Problem about Polyline// Codeforces Round #320 (Div. 1)

    题意:一个等腰直角三角形一样的周期函数(只有x+轴),经过给定的点(a,b),并且半周期为X,使X尽量大,问X最大为多少? 如果a=b,结果就为b 如果a<b无解. 否则,b/(2*k*x-a) ...

  7. codeforces 578c//Weakness and Poorness// Codeforces Round #320 (Div. 1)

    题意:一个数组arr,一个数字x,要使arr-x的最大子段最小,问该最小值. 三分x,复杂度logn,内层是最大子段的模板,只能用n复杂度的.因为是绝对值最大,正负各求一次,取大的.精度卡得不得了,要 ...

  8. codeforces 578b//"Or" Game// Codeforces Round #320 (Div. 1)

    题意:n个数字,最多操作k次,每次乘x,要使结果数组的与值最大. 能推断出结果是对一个元素操作k次,并且这个元素的二进制最高位比较大.并不一定是取最大的,比如1100和1010,乘以一次2,两种选法分 ...

  9. Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] E. Weakness and Poorness 三分

    E. Weakness and Poorness time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

随机推荐

  1. Spring+Maven+Dubbo+MyBatis+Linner+Handlebars—Web开发环境搭建

    本文主要分三部分,分别是:后台核心业务逻辑.桥梁辅助控制和前台显示页面. 本Web开发环境综合了多种工具,包括Maven包管理与编译工具.Dubbo分布式服务框架.MyBatis数据持久化工具.Lin ...

  2. 与你相遇好幸运,Tippecanoe在Centos下の安装

    全新的CentOS 7 x86_64 安装编译工具 yum install -y gcc automake autoconf libtool make yum insyall -y gcc gcc-c ...

  3. Pyqt 一个简单的浏览器

    使用QtWebKit 做一个简单的浏览器. mybrowserUI.ui <?xml version="1.0" encoding="UTF-8"?> ...

  4. 讲解JS的promise,这篇是专业认真的!

    http://www.zhangxinxu.com/wordpress/2014/02/es6-javascript-promise-%E6%84%9F%E6%80%A7%E8%AE%A4%E7%9F ...

  5. Linux进程状态 ( Linux Process State Codes)

    进程状态代码及说明: STATE代码 说明 D 不可中断的睡眠. 通常是处于I/O之中. R 运行中/可运行. 正处于运行队列中. S 可中断的睡眠. 等待某事件发生. T 已停止. 可能是因为she ...

  6. 攻城狮在路上(贰) Spring(四)--- Spring BeanFactory简介

    BeanFactory时Spring框架最核心的接口,它提供了高级IoC的配置机制,使管理不同类型的Java对象成为了可能.我们一般称BeanFactory为IoC容器.BeanFactory是Spr ...

  7. 修改tomcat默认编码

    实际项目中一般是用utf-8的,而Tomcat的默认编码则是iso-8859-1, 因此我们通常编辑conf/下的server.xml,配置Connector项,加上属性URIEncoding=&qu ...

  8. Win10 启动模拟器

    不知道怎么解决 答:去bios里设置了.开启了虚拟化hyper,重启.

  9. WPF ItemsControl ListBox ListView比较

    在进行列表信息展示时,WPF中提供多种列表可供选择.这篇博客将对WPF ItemsControl, ListBox, ListView进行比较. 相同点: 1. 这三个控件都是列表型控件,可以进行列表 ...

  10. 第十七篇:使用窗口的cache属性加速SOUI的渲染

    内容渲染速度是决定一个UI成败的关键.无论UI做得多华丽,没有速度都没有意义. 在MFC,WTL等开发框架下,每个控件都是一个窗口,窗口只需要画前景,背景.因为窗口之间的内容不需要做混合,一个子窗口的 ...