Codeforces Round #243 (Div. 2) A~C
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.
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.
In a single line, print "YES" (without the quotes) if his friends can play in the described manner, and "NO" (without the quotes) otherwise.
3 4
1 1 1
YES
3 4
3 1 3
YES
3 4
4 4 4
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?
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.
In the single line, print the answer to the problem — the minimum number of rows of matrix b.
4 3
0 0 1
1 1 0
1 1 0
0 0 1
2
3 3
0 0 0
0 0 0
0 0 0
3
8 1
0
1
1
0
0
1
1
0
2
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中,行最少的那一个。
#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?
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).
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.
10 2
10 -1 2 2 2 2 2 2 -1 10
32
5 10
-1 -1 -1 -1 -1
-1
题意 : 给了两个公式能够求出m(a),然后允许最多交换k次,求其中的最大的m(a)。
#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的更多相关文章
- Codeforces Round #243 (Div. 2) B(思维模拟题)
http://codeforces.com/contest/426/problem/B B. Sereja and Mirroring time limit per test 1 second mem ...
- Codeforces Round #243 (Div. 1) A题
http://codeforces.com/contest/425/problem/A 题目链接: 然后拿出这道题目是很多人不会分析题目,被题目吓坏了,其中包括我自己,想出复杂度,一下就出了啊!真是弱 ...
- Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读
http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps
由于n比较小,直接暴力解决 #include <iostream> #include <vector> #include <algorithm> #include ...
- Codeforces Round #243 (Div. 2) B. Sereja and Mirroring
#include <iostream> #include <vector> #include <algorithm> using namespace std; in ...
- Codeforces Round #243 (Div. 2) A. Sereja and Mugs
#include <iostream> #include <vector> #include <algorithm> #include <numeric> ...
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps(优先队列 暴力)
题目 题意:求任意连续序列的最大值,这个连续序列可以和其他的 值交换k次,求最大值 思路:暴力枚举所有的连续序列.没做对是因为 首先没有认真读题,没看清交换,然后,以为是dp或者贪心 用了一下贪心,各 ...
- Codeforces Round #243 (Div. 1)-A,B,C-D
此CF真是可笑.. . 由于早晨7初始点,因此,要做好CF时间已经17没有休息一小时,加上中午5小时耐力赛. 心里很清楚.是第一个问题的时候,几乎被解读为寻求最大的领域和.然后找到一个水体,快速A降. ...
- Codeforces Round #243 (Div. 2)——Sereja and Swaps
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u012476429/article/details/24665103 题目链接 题意: 给定一个整数 ...
随机推荐
- NDIS IM 驱动那些事情
最近不知道为什么开始学习windows NDIS驱动开发,用的是寒江独钓的例子,其实他的改的代码也就一点点,说的有用的东西也就那么多,不过还是感谢他出了这么一本书,不然这真的就没有一本稍微好一点的书籍 ...
- ios开发:GCD多线程
ios有三种多线程编程技术,分别是NSThread,Cocoa NSOperation和GCD,GCD全称Grand Central Dispatch 是Apple开发的一个多核编程的解决方法,在iO ...
- PHP标签的格式
PHP标签的格式: 1.xml格式(推荐的,标准的标记) <?php php代码?> 示例: 2.短格式 <? php代码 ?> 此种格式需要在php.ini中配置 示例 ...
- linux同步
1. 内核同步 主要是防止多核处理器同时访问修改某段代码,或者在对设备驱动程序进行临界区的保护. 1 .互斥量 头文件 #include<linux/mutex.h> 初始化方法: 静态初 ...
- bzoj 1040 骑士
这题真不爽,各种WA,写个题解浏览器还挂了,真不爽. 所以不多说了,就说关于判断是否是父节点的问题,不能直接判,会有重边,这种情况只能用编号判,传进去入边的编号,(k^1) != fa,这样就可以了. ...
- JAVA_SE复习(OOP1)
面向对象编程(一) 一.继承 1. 在类图表示中,使用一个分为三块的矩形表示一个类.矩形的第一块表示类名,第二块描述这个类的属性及属性的数据类型,第三块描述这个类的操作,也就是方法以及返回类型. ...
- 多项分布(multinominal distribution)
简介 更一般性的问题会问:“点数1~6的出现次数分别为(x1,x2,x3,x4,x5,x6)时的概率是多少?其中sum(x1~x6)= n”.这就是一个多项式分布. 定义 把二项分布推广至多个(大于2 ...
- C#如何获取快捷方式指向的目标文件
前几天,做个小程序时遇到的问题,在百度上搜索了很久,没有发现好的解决方案,在英文网站上立刻搜到办法,看来还是国外的资源要全面一些,只是Google经常访问不正常,没办法啊. “C#如何获取快捷方式指向 ...
- ajaxFileUpload - Post file and data together
jQuery.extend({ createUploadIframe: function(id, uri) { //create frame var frameId = 'jUploadFrame' ...
- C# 从服务器下载文件代码的几种方法
一.//TransmitFile实现下载 protected void Button1_Click(object sender, EventArgs e) { /* 微软为Response对象提供了一 ...