题目链接

A. Squats

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster either sat down or stood up.

For another exercise, Pasha needs exactly  hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well?

Input

The first line contains integer n (2 ≤ n ≤ 200; n is even). The next line contains n characters without spaces. These characters describe the hamsters' position: the i-th character equals 'X', if the i-th hamster in the row is standing, and 'x', if he is sitting.

Output

In the first line, print a single integer — the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them.

Sample test(s)
input
4
xxXx
output
1
XxXx
input
2
XX
output
1
xX
input
6
xXXxXx
output

0
xXXxXx

题意 : X代表站着,x代表蹲着,要求n只中正好有一半是蹲着一半是站着,让一只仓鼠由蹲变为站或由站变为蹲需要1分钟,问最少需要多少分钟能够达到要求。

思路 : 水题不详述,一开始还因为题中的那个1分钟让一些仓鼠换状态,有一些疑惑,后来就直接当成让一个,然后就过了。
 #include <stdio.h>
#include <string.h>
#include <iostream> using namespace std ;
char sh[] ;
int main()
{
int n ;
while(~scanf("%d",&n))
{
scanf("%s",sh) ;
int cnt = ;
for(int i = ; i < n ; i++)
if(sh[i] == 'X')
cnt++ ;
if(cnt == n/)
{
printf("0\n%s\n",sh) ;
}
else if(cnt > n/)
{
printf("%d\n",cnt-n/) ;
for(int i = ,k = ; i < n && k < cnt-n/ ; i++)
if(sh[i] == 'X')
{
sh[i] = 'x';
k++ ;
}
printf("%s\n",sh) ;
}
else if(cnt < n/)
{
printf("%d\n",n/-cnt) ;
for(int i = ,k = ; i < n && k < n/-cnt ; i++)
if(sh[i] == 'x')
{
sh[i] = 'X';
k++ ;
}
printf("%s\n",sh) ;
}
}
return ;
}

B. Megacity

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city.

The city of Tomsk can be represented as point on the plane with coordinates (0; 0). The city is surrounded with n other locations, the i-th one has coordinates (xiyi) with the population of ki people. You can widen the city boundaries to a circle of radius r. In such case all locations inside the circle and on its border are included into the city.

Your goal is to write a program that will determine the minimum radius r, to which is necessary to expand the boundaries of Tomsk, so that it becomes a megacity.

Input

The first line of the input contains two integers n and s (1 ≤ n ≤ 103; 1 ≤ s < 106) — the number of locatons around Tomsk city and the population of the city. Then n lines follow. The i-th line contains three integers — the xi and yi coordinate values of the i-th location and the number ki of people in it (1 ≤ ki < 106). Each coordinate is an integer and doesn't exceed 104 in its absolute value.

It is guaranteed that no two locations are at the same point and no location is at point (0; 0).

Output

In the output, print "-1" (without the quotes), if Tomsk won't be able to become a megacity. Otherwise, in the first line print a single real number — the minimum radius of the circle that the city needs to expand to in order to become a megacity.

The answer is considered correct if the absolute or relative error don't exceed 10 - 6.

Sample test(s)
input
4 999998
1 1 1
2 2 1
3 3 1
2 -2 1
output
2.8284271
input
4 999998
1 1 2
2 2 1
3 3 1
2 -2 1
output
1.4142136
input
2 1
1 1 999997
2 2 1
output

-1

题意 : 周围有n个城市,这个城市目前有k个人,这个城市要往外扩充,来让人数达到1000000,以0,0为圆心,问你找一个半径为r的圆,要使r尽量小并且这个城市扩充之后的人数至少为1000000 。

思路 : 把这n个城市到圆心的距离排一下序,从最近的开始加。
 #include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <iostream> using namespace std ; struct node
{
double x,y ;
int num ;
} p[]; int cmp(const node &a,const node &b)
{
if(sqrt(a.x*a.x+a.y*a.y) == sqrt(b.x*b.x+b.y*b.y))
return a.num > b.num ;
return sqrt(a.x*a.x+a.y*a.y) < sqrt(b.x*b.x+b.y*b.y) ;
}
int main()
{
int n , k;
while(~scanf("%d %d",&n,&k))
{
int sum = ;
for(int i = ; i < n ; i++)
{
scanf("%lf %lf %d",&p[i].x,&p[i].y,&p[i].num) ;
sum += p[i].num ;
}
if(sum + k < )
{
printf("-1\n") ;
continue ;
}
sort(p,p+n,cmp) ;
int cnt = -k,j,i ;
for(i = ,j = cnt; i < n && j >= ; i++)
{
if(p[i].num >= j)
break ;
else {
j -= p[i].num ;
} }
printf("%.7lf\n",sqrt(p[i].x*p[i].x+p[i].y*p[i].y)) ;
}
return ;
}

C. Magic Formulas

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

People in the Tomskaya region like magic formulas very much. You can see some of them below.

Imagine you are given a sequence of positive integer numbers p1, p2, ..., pn. Lets write down some magic formulas:

Here, "mod" means the operation of taking the residue after dividing.

The expression  means applying the bitwise xor (excluding "OR") operation to integers x and y. The given operation exists in all modern programming languages. For example, in languages C++ and Java it is represented by "^", in Pascal — by "xor".

People in the Tomskaya region like magic formulas very much, but they don't like to calculate them! Therefore you are given the sequence p, calculate the value of Q.

Input

The first line of the input contains the only integer n (1 ≤ n ≤ 106). The next line contains n integers: p1, p2, ..., pn (0 ≤ pi ≤ 2·109).

Output

The only line of output should contain a single integer — the value of Q.

Sample test(s)
input
3
1 2 3
output

3

题意 : 给你p1,p2.....pn,根据给定的两个式子,让你求出Q 。

思路 : 如果直接求肯定超时,所以要另辟蹊径。不能一行一行的异或,要一列一列的异或,等列出表就可以轻易的观察出规律。还有一个数异或上0还是本身。
从这个表中可以看出每一列的规律,所以异或的时候一列一列的去异或,因为如果你异或上两个相同的数还是本身,所以每一列要找重复周期,如果周期为偶数,那就不用异或,如果为偶数但是余数不为0,可以看出3那一列就是周期数为偶数但是余数为1,就要再异或上这个1,当然有的时候剩的不止是1,但是剩下的数一定从一开始,所以要提前打个表。
我的代码
 #include <stdio.h>
#include <iostream>
#include <string.h> using namespace std ; long long a[] ;
long long m ; void table()
{
a[] = ;
a[] = ;
for(int i = ; i < ; i++)
a[i] = a[i-] ^ i ;
} int main()
{
int n ;
table() ;
while(~scanf("%d",&n))
{
long long sum = ;
for(int i = ; i <= n ; i++)
{
scanf("%I64d",&m) ;
sum = sum ^ m ;
}
for(int i = ; i <= n ; i++)
{
int rest = n % i ;
int t = n / i ;
if(t % )
{
sum ^= a[i-] ;
if(rest != )
sum ^= a[rest] ;
}
else
{
if(rest != )
sum ^= a[rest] ;
}
}
printf("%I64d\n",sum) ;
}
return ;
}

这个代码其实有更为简单的写法。。。。。

 #include<stdio.h>

 long long sum,a[],n,m;

 int main()
{
while(~scanf("%I64d",&n))
{
for(int i = ; i <= n ; i++)
{
a[i] = a[i-] ^ i ;
scanf("%I64d",&m) ;
sum ^= m ^ a[n % i] ^ ( n / i % ? a[i-] : );
}
printf("%I64d\n",sum) ;
}
return ;
}

很神奇有没有。。。。

Codeforces Round #242 (Div. 2) A~C的更多相关文章

  1. Codeforces Round #242 (Div. 2) C题

    题目链接:http://codeforces.com/contest/424/problem/C, 想来一个小时,就是做不出,都做出来了,悲剧! 分析:我们知道交换异或的顺序不影响答案! 然后就是求t ...

  2. Codeforces Round #242 (Div. 2) A. Squats

    注意题目一次只能改变一个松鼠,Pasha can make some hamster ether sit down or stand up.是单数不是复数 #include <iostream& ...

  3. Codeforces Round #242 (Div. 2) B. Megacity

    按照半径排序,然后累加人数直到超过百万 #include <iostream> #include <algorithm> #include <cmath> #inc ...

  4. Codeforces Round #242 (Div. 2) C. Magic Formulas

    解题思路是: Q=q1^q2.......^qn = p1^p2......^pn^((1%1)^....(1%n))^((2%1)^......(2%n))^.... 故Q的求解过程分成两部分 第一 ...

  5. Codeforces Round #242 (Div. 2) C. Magic Formulas (位异或性质 找规律)

    题目 比赛的时候找出规律了,但是找的有点慢了,写代码的时候出了问题,也没交对,还掉分了.... 还是先总结一下位移或的性质吧: 1.  交换律 a ^ b = b ^ a 2. 结合律 (a^b) ^ ...

  6. Codeforces Round #242 (Div. 2) &lt;A-D&gt;

    CF424 A. Squats 题目意思: 有n(n为偶数)个x和X,求最少的变换次数,使得X的个数为n/2,输出变换后的序列. 解题思路: 统计X的个数ans,和n/2比較,少了的话,须要把n/2- ...

  7. Codeforces Round #242 (Div. 2)C(找规律,异或运算)

    一看就是找规律的题.只要熟悉异或的性质,可以秒杀. 为了防止忘记异或的规则,可以把异或理解为半加运算:其运算法则相当于不带进位的二进制加法. 一些性质如下: 交换律: 结合律: 恒等律: 归零律: 典 ...

  8. Codeforces Round #258 (Div. 2)[ABCD]

    Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意 ...

  9. Codeforces Round #257 (Div. 1)A~C(DIV.2-C~E)题解

    今天老师(orz sansirowaltz)让我们做了很久之前的一场Codeforces Round #257 (Div. 1),这里给出A~C的题解,对应DIV2的C~E. A.Jzzhu and ...

随机推荐

  1. Build Firefox 编译Firefox

    准备 选择需要的firefox版本 http://hg.mozilla.org/releases/ 选择最新的build工具 http://ftp.mozilla.org/pub/mozilla.or ...

  2. SVN Application

    一.SVN客户端:TortoiseSvn 下载地址: http://tortoisesvn.net/downloads.html 安装完后重启, 右击就可以使用SVN命令 首先, 从服务器版本库那边 ...

  3. 从客户端中检测到有潜在危险的 request

    如题,当遇到这种情况该怎么办呢? 通常情况下一下2种解决方案就可以解决问题了:    解决方案一:     在.aspx文件头中加入这句:     <%@ Page validateReques ...

  4. WINDOWS2008 设置FTP防火墙规则

    在防火墙入站规划这里,加上21.20两个端口. 然后重启ftp服务,cmd命令:net stop ftpsvc & net start ftpsvc(重启ftp服务) 一定要重启ftp服务,不 ...

  5. c#基础笔记-----------集合

    首先所谓集合是用于管理对象的容器类.一方面集合将独立的对象汇集成群集,作为一个群集来管理,以便进行整体性操作:而另一方面,集合可以方便地获取群集中的个体,进行个体化操作.在.Net中,集合被封装为对象 ...

  6. SSH连接时出现Host key verification failed的原因及解决方法

    SSH连接的时候Host key verification failed. [root@cache001 swftools-0.9.0]# ssh 192.168.1.90@@@@@@@@@@@@@@ ...

  7. 第七章 探秘Qt的核心机制-信号与槽

    第七章 探秘Qt的核心机制-信号与槽 注:要想使用Qt的核心机制信号与槽,就必须在类的私有数据区声明Q_OBJECT宏,然后会有moc编译器负责读取这个宏进行代码转化,从而使Qt这个特有的机制得到使用 ...

  8. 5步解决移动设备上的300ms点击延迟

    译者:jmouse 大多数基于触摸的浏览器设备,在点击时都会有个 300ms 的事件触发等待时间,做过 web app 开发的同学应该都遇到过这个情况,通过下面的5步可以轻松搞定这个延迟. 1.不要太 ...

  9. python(三)一个文件读写操作的小程序

    我们要实现一个文件读写操作的小程序 首先我们有一个文件 我们要以"============"为界限,每一个角色分割成一个独立的txt文件,按照分割线走的话是分成 xiaoNa_1. ...

  10. jquery nicescroll 配置参数

    jQuery滚动条插件兼容ie6+.手机.ipad http://www.areaaperta.com/nicescroll/ jQuery(function($){ $("#scrollI ...