题目链接

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. 理解CPU内存管理

    概述:从设计层面理解CPU的内存模式,包括段式内存管理.页式内存管理以及虚拟化扩展内存管理.实际上,硬件支持与软件实现从来就不是能分开讲的,比如,Intel CPU架构师在选择CPU的硬件特性时,必然 ...

  2. 第五十六篇、OC打开本地和网络上的word、ppt、excel、text等文件

    iOS打开本地和网络上的word.ppt.excel.text等文件 iOS开发过程中可能需要预览一些文件,这些文件的格式可能有word.ppt.excel等文件格式.那么系统提供两个类去预览这些文件 ...

  3. 第四十三篇、利用NSProxy解决NSTimer内存泄漏问题

    问题描述: 用NSTimer来实现每隔一定时间执行制定的任务,例如最常见的广告轮播图.如果我们在 timerWithTimeInterval:1 target:self 中指定target为当前控制器 ...

  4. 第三十篇、iOS开发中常用的宏

    //字符串是否为空 #define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str leng ...

  5. PHP学习笔记 - 入门篇(2)

    PHP入门篇(2) 什么是变量 变量是用于存储值的容器,如下 $var = @"6666" 如何定义变量 定义变量就是像服务器的内存申请空间,用来存储数据,eg: <?php ...

  6. swift闭包传值

    不知道原理,就知道这么用的,皮毛上的那一点. 寻思着把以前的项目改成swift的,结果了,,, 反向传值 一. //类似于OC中的typedef typealias sendValueClosure= ...

  7. AE实现矢量图层标注属性

    添加引用ESRI.ArcGIS.Carto 1.获取图层 IGeoFeatureLayer pFtrLayer = m_pLayer as IGeoFeatureLayer; 2.初始化标注属性集合 ...

  8. Fuck Flyme Theme

    转载说明 本篇文章可能已经更新,最新文章请转:http://www.sollyu.com/fuck-flyme-theme/ 说明 本插件仅用于魅蓝Note, MX3, MX4, MX4 PRO它机型 ...

  9. alter和alert的一些问题

    今天在Java学习群里看到有人问:用alert能不能修改表结构?我第一反应是,alert是弹窗啊,怎么修改表结构?后来再看才知道,是那人打错了!我也晕了一下,还是记一下吧!alter是修改表结构的,a ...

  10. [译]Java Thread join示例与详解

    Java Thread join示例与详解 Java Thread join方法用来暂停当前线程直到join操作上的线程结束.java中有三个重载的join方法: public final void ...