题目链接

A. Sereja and Mugs

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

Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and n water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume that this player lost.

As soon as Sereja's friends heard of the game, they wanted to play it. Sereja, on the other hand, wanted to find out whether his friends can play the game in such a way that there are no losers. You are given the volumes of all mugs and the cup. Also, you know that Sereja has (n - 1) friends. Determine if Sereja's friends can play the game so that nobody loses.

Input

The first line contains integers n and s (2 ≤ n ≤ 100; 1 ≤ s ≤ 1000) — the number of mugs and the volume of the cup. The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 10). Number ai means the volume of the i-th mug.

Output

In a single line, print "YES" (without the quotes) if his friends can play in the described manner, and "NO" (without the quotes) otherwise.

Sample test(s)
input
3 4
1 1 1
output
YES
input
3 4
3 1 3
output
YES
input
3 4
4 4 4
output
NO

题意 : 大意大概是有很多n个小杯,1大杯,每个小杯的容积以及大杯的容积都知道了,游戏规则是,每个人拿一个非空的小杯,把水全部倒大杯里,如果谁倒的时候大杯满了,谁就输,然后她的(n-1)个朋友要玩儿,问你有没有一种倒水的方法使得没有人会输,如果没有输出NO。

思路 : 一开始以为她自己也玩儿,就不知道第二组样例为什么对了,后来又看了一遍题,觉得应该是光朋友玩儿,就试了一下儿,结果对了。。。。。

 #include <stdio.h>
#include <iostream>
#include <algorithm> using namespace std ; int a[] ; int main()
{
int n,s ;
while(~scanf("%d %d",&n,&s))
{
for(int i = ; i < n ; i++)
scanf("%d",&a[i]) ;
sort(a,a+n) ;
int sum = ;
bool flag = false ;
for(int i = ; i < n- ; i++)
{
sum += a[i] ;
if(sum > s)
{
flag = true ;
break ;
}
}
if(flag)
puts("NO") ;
else puts("YES") ;
}
return ;
}

B. Sereja and Mirroring

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

Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a2x × y matrix c which has the following properties:

  • the upper half of matrix c (rows with numbers from 1 to x) exactly matches b;
  • the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1).

Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several(possibly zero) mirrorings. What minimum number of rows can such matrix contain?

Input

The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a.

Output

In the single line, print the answer to the problem — the minimum number of rows of matrix b.

Sample test(s)
input
4 3
0 0 1
1 1 0
1 1 0
0 0 1
output
2
input
3 3
0 0 0
0 0 0
0 0 0
output
3
input
8 1
0
1
1
0
0
1
1
0
output
2
Note

In the first test sample the answer is a 2 × 3 matrix b:

001
110

If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:

001
110
110
001

题意 :这个破题读了好久,我严重怀疑我近段时间的英语水平。就是说一个大小为x*y的矩阵b的mirroring定义为一个大小为2x*y的矩阵,前x行与b相同,后x行与前x行对称,然后给你一个n*m的矩阵,让你求一个矩阵b,使得b经过几次或0次mirroring后能够得到a,让你输出成立的b中,行最少的那一个。

思路 : 这个题的话要先判断一下,如果是mirroring的话,行一定是偶数,如果不是偶数,说明是通过0次mirroring操作的,所以最小就是它自己,然后就一直除以2进行枚举,判断一下是否是偶数,是否对称,如果对称就继续下去,看能不能更小,如果不对称就直接在这儿就行。。。。。
 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <string> using namespace std ; int a[][] ;
char str[][] ; int main()
{
int n,m ;
while(~scanf("%d %d",&n,&m))
{
for(int i = ; i < n ; i++)
for(int j = ; j < m ; j++)
scanf("%d",&a[i][j]) ;
if(n % )
{
cout<<n<<endl ;
continue ;
}
int mid ;
while(true)
{
mid = n >> ;
bool flag = true;
for(int i = ; i < mid ; i++)
{
int j = n-i- ;
for(int k = ; k < m ; k++)
{
if(a[i][k] != a[j][k])
{
flag = false ;
break ;
}
}
if(!flag)
break ;
}
if(!flag)
{
printf("%d\n",mid*) ;
break ;
}
else
{
if(mid % )
{
cout<<mid<<endl ;
break ;
}
else
n = n >> ;
}
}
}
return ;
}

C. Sereja and Swaps

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

As usual, Sereja has array a, its elements are integers: a[1], a[2], ..., a[n]. Let's introduce notation:

A swap operation is the following sequence of actions:

  • choose two indexes i, j (i ≠ j);
  • perform assignments tmp = a[i], a[i] = a[j], a[j] = tmp.

What maximum value of function m(a) can Sereja get if he is allowed to perform at most k swap operations?

Input

The first line contains two integers n and k (1 ≤ n ≤ 200; 1 ≤ k ≤ 10). The next line contains n integers a[1], a[2], ..., a[n] ( - 1000 ≤ a[i] ≤ 1000).

Output

In a single line print the maximum value of m(a) that Sereja can get if he is allowed to perform at most k swap operations.

Sample test(s)
input
10 2
10 -1 2 2 2 2 2 2 -1 10
output
32
input
5 10
-1 -1 -1 -1 -1
output

-1

题意 : 给了两个公式能够求出m(a),然后允许最多交换k次,求其中的最大的m(a)。

思路 : 这个题看了二师兄的代码,瞬间对二师兄膜拜啊。大概应该是这样的,两个for循环先枚举(l,r)区间能够得到的最大值,并且把这些数存到容器里。然后肯定还有(1,l-1)和(r+1,n)这里边还有数,把这些数存到容器里,然后枚举交换次数,从第二个容器里找出最大值看是否比第一个容器的最小值大,那就交换。
 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector> using namespace std ; int a[] ; int main()
{
int n ,k;
while(~scanf("%d %d",&n,&k))
{
for(int i = ; i <= n ; i++)
scanf("%d",&a[i]) ;
int maxx = -,sum ;
for(int i = ; i <= n ; i++)
{
for(int j = i ; j <= n ; j++)
{
sum = ;
vector<int > v ,u;
for(int h = i ; h <= j ; h++)
{
v.push_back(a[h]) ;
sum += a[h] ;
}
maxx = max(maxx,sum) ;
for(int h = ; h <= n ; h++)
{
if(h < i || h > j)
u.push_back(a[h]) ;
}
sort(v.begin(),v.end()) ;
sort(u.begin(),u.end()) ;
reverse(u.begin(),u.end()) ;
for(int h = ; h <= k && h <= v.size() && h <= u.size() ; h++)//枚举交换次数
{
if(v[h-] < u[h-])
{
sum -= v[h-] ;
sum += u[h-] ;
maxx = max(sum,maxx) ;
}
}
}
}
printf("%d\n",maxx) ;
}
return ;
}

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

  1. Codeforces Round #243 (Div. 2) B(思维模拟题)

    http://codeforces.com/contest/426/problem/B B. Sereja and Mirroring time limit per test 1 second mem ...

  2. Codeforces Round #243 (Div. 1) A题

    http://codeforces.com/contest/425/problem/A 题目链接: 然后拿出这道题目是很多人不会分析题目,被题目吓坏了,其中包括我自己,想出复杂度,一下就出了啊!真是弱 ...

  3. Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读

    http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...

  4. Codeforces Round #243 (Div. 2) C. Sereja and Swaps

    由于n比较小,直接暴力解决 #include <iostream> #include <vector> #include <algorithm> #include ...

  5. Codeforces Round #243 (Div. 2) B. Sereja and Mirroring

    #include <iostream> #include <vector> #include <algorithm> using namespace std; in ...

  6. Codeforces Round #243 (Div. 2) A. Sereja and Mugs

    #include <iostream> #include <vector> #include <algorithm> #include <numeric> ...

  7. Codeforces Round #243 (Div. 2) C. Sereja and Swaps(优先队列 暴力)

    题目 题意:求任意连续序列的最大值,这个连续序列可以和其他的 值交换k次,求最大值 思路:暴力枚举所有的连续序列.没做对是因为 首先没有认真读题,没看清交换,然后,以为是dp或者贪心 用了一下贪心,各 ...

  8. Codeforces Round #243 (Div. 1)-A,B,C-D

    此CF真是可笑.. . 由于早晨7初始点,因此,要做好CF时间已经17没有休息一小时,加上中午5小时耐力赛. 心里很清楚.是第一个问题的时候,几乎被解读为寻求最大的领域和.然后找到一个水体,快速A降. ...

  9. Codeforces Round #243 (Div. 2)——Sereja and Swaps

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u012476429/article/details/24665103 题目链接 题意: 给定一个整数 ...

随机推荐

  1. 资源汇集:nginx教程从入门到精通

    http://linux.cn/article-4279-1.html

  2. 第二篇、JavaScript常用的API

    下面是我整理的一些JavaScript常用的API清单. 目录 元素查找 class操作 节点操作 属性操作 内容操作 css操作 位置大小 事件 DOM加载完毕 绑定上下文 去除空格 Ajax JS ...

  3. XML解析的例子

    ////  main.m//  homewoek////  Created by hehe on 15/9/9.//  Copyright (c) 2015年 wang.hehe. All right ...

  4. ECMAScript 5.1 Edition DOC 学习笔记

    1.类型 string number object boolean null undefined symbol (es6) attention : (typeof null) 值为 'object', ...

  5. DTcms列表隔行换色;loop自带行号

    <%loop cdr2 bcategoryList%> <%if(cdr2__loop__id==1)%> <a class="no-bg" href ...

  6. TCP三次握手原理与SYN攻击

    本文内容包括以下几点 1.TCP三次握手四次挥手解析 2.迭代型服务器程序编写,并给出客户端,结合这一模式详细介绍Berkeley套接字的使用 3.介绍SYN攻击的原理 TCP连接建立,传输数据,连接 ...

  7. [Linux]学习笔记(3)-uname的用法

    uname的用法如下: uname –a[--all]:输出全部信息 [root@linuxforlijiaman ~]# uname -a Linux linuxforlijiaman -.el6. ...

  8. python装饰器总结

    一.装饰器是什么 python的装饰器本质上是一个Python函数,它可以让其他函数在不需要做任何代码变动的前提下增加额外功能,装饰器的返回值也是一个函数对象.简单的说装饰器就是一个用来返回函数的函数 ...

  9. Linux tar 解压缩命令

    tar -c: 建立压缩档案 -x:解压 -t:查看内容 -r:向压缩归档文件末尾追加文件 -u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个 ...

  10. H264相关代码

    H.264格式的视频打包成RTP后进行发送,编译环境为VC6++ #include <stdio.h> #include <stdlib.h> #include <str ...