题目链接

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. Cocos2d-x开发实例介绍帧动画使用

    下面我们通过一个实例介绍一下帧动画的使用,这个实例如下图所示,点击Go按钮开始播放动画,这时候播放按钮标题变为Stop,点击Stop按钮可以停止播放动画. 下面我们再看看具体的程序代码,首先看一下看H ...

  2. APC -- Asynchronous Procedure Call 异步过程调用

    异步过程调用(APC -- Asynchronous Procedure Call )是一种与常用的和简单的同步对象不同的一种同步机制. 我们在我们线程里使用基本的同步对象如MUTEX去通知其它线程, ...

  3. jqGrid Tree

    CSS: <!--jqGrid--><link rel="stylesheet" href="plugins/jqgird/css/ui.jqgrid. ...

  4. robolectric环境的搭建

    最近在学习测试驱动开发(Test-Driven Development),测试驱动开始是极限编程的一种方式,提倡在真正编写代码之前先根据需求编写测试代码(当然这个测试代码是不可能通过的),然后根据测试 ...

  5. An Easy Task

    An Easy Task Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

  6. [java学习笔记]java语言核心----面向对象之static关键字

    static关键字用处 用于修饰成员变量和成员函数 被修饰后的成员具有以下特点: 随着类的加载而加载 优先于对象存在 被所有对象所共享 可以直接被类名调用 使用注意 静态方法只能访问静态成员:非静态方 ...

  7. bind()实现

    bind()函数是在 ECMA-262 第五版才被加入:它可能无法在所有浏览器上运行.这就需要我们自己实现bind()函数了 简单实现bind()方法: Function.prototype.bind ...

  8. IIS上的错误与解决方案

    1.未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序. 解决方案:在IIS上打开该网站应用程序池-->高级设置-->启动32位程序-->选True

  9. 中科红旗倒下,谁来挑战windows

    中科红旗解散 国产操作系统从此梦断 2月10日,关门上锁的中科红旗北京总部大门上粘贴了一张最新公告,这张公告彻底击破了那些仍然坚守公司工作的员工“拯救中国红旗”的希望.该公告称:因北京中科红旗软件技术 ...

  10. php入门变量之字符串

    字符串只是一块用引号括起来的字符:字母.数字.空格.标点符号,等等. 下面列出的全都是字符串: 'Huige' "In watermelon sugar" '100' 'Augus ...