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 41 1 1
YES
3 43 1 3
YES
3 44 4 4
NO
题意 : 大意大概是有很多n个小杯,1大杯,每个小杯的容积以及大杯的容积都知道了,游戏规则是,每个人拿一个非空的小杯,把水全部倒大杯里,如果谁倒的时候大杯满了,谁就输,然后她的(n-1)个朋友要玩儿,问你有没有一种倒水的方法使得没有人会输,如果没有输出NO。
思路 : 一开始以为她自己也玩儿,就不知道第二组样例为什么对了,后来又看了一遍题,觉得应该是光朋友玩儿,就试了一下儿,结果对了。。。。。
1 #include <stdio.h> 2 #include <iostream> 3 #include <algorithm> 4 5 using namespace std ; 6 7 int a[110] ; 8 9 int main() 10 { 11 int n,s ; 12 while(~scanf("%d %d",&n,&s)) 13 { 14 for(int i = 0 ; i < n ; i++) 15 scanf("%d",&a[i]) ; 16 sort(a,a+n) ; 17 int sum = 0 ; 18 bool flag = false ; 19 for(int i = 0 ; i < n-1 ; i++) 20 { 21 sum += a[i] ; 22 if(sum > s) 23 { 24 flag = true ; 25 break ; 26 } 27 } 28 if(flag) 29 puts("NO") ; 30 else puts("YES") ; 31 } 32 return 0 ; 33 }
View Code
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 30 0 11 1 01 1 00 0 1
2
3 30 0 00 0 00 0 0
3
8 101100110
2
In the first test sample the answer is a 2 × 3 matrix b:
001110
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中,行最少的那一个。
1 #include <stdio.h> 2 #include <string.h> 3 #include <iostream> 4 #include <string> 5 6 using namespace std ; 7 8 int a[110][110] ; 9 char str[110][110] ; 10 11 int main() 12 { 13 int n,m ; 14 while(~scanf("%d %d",&n,&m)) 15 { 16 for(int i = 0 ; i < n ; i++) 17 for(int j = 0 ; j < m ; j++) 18 scanf("%d",&a[i][j]) ; 19 if(n % 2) 20 { 21 cout<<n<<endl ; 22 continue ; 23 } 24 int mid ; 25 while(true) 26 { 27 mid = n >> 1 ; 28 bool flag = true; 29 for(int i = 0 ; i < mid ; i++) 30 { 31 int j = n-i-1 ; 32 for(int k = 0 ; k < m ; k++) 33 { 34 if(a[i][k] != a[j][k]) 35 { 36 flag = false ; 37 break ; 38 } 39 } 40 if(!flag) 41 break ; 42 } 43 if(!flag) 44 { 45 printf("%d\n",mid*2) ; 46 break ; 47 } 48 else 49 { 50 if(mid % 2) 51 { 52 cout<<mid<<endl ; 53 break ; 54 } 55 else 56 n = n >> 1 ; 57 } 58 } 59 } 60 return 0 ; 61 }
View Code
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 210 -1 2 2 2 2 2 2 -1 10
32
5 10-1 -1 -1 -1 -1
-1
题意 : 给了两个公式能够求出m(a),然后允许最多交换k次,求其中的最大的m(a)。
1 #include <stdio.h> 2 #include <string.h> 3 #include <iostream> 4 #include <algorithm> 5 #include <vector> 6 7 using namespace std ; 8 9 int a[1010] ; 10 11 int main() 12 { 13 int n ,k; 14 while(~scanf("%d %d",&n,&k)) 15 { 16 for(int i = 1 ; i <= n ; i++) 17 scanf("%d",&a[i]) ; 18 int maxx = -9999999,sum ; 19 for(int i = 1 ; i <= n ; i++) 20 { 21 for(int j = i ; j <= n ; j++) 22 { 23 sum = 0 ; 24 vector<int > v ,u; 25 for(int h = i ; h <= j ; h++) 26 { 27 v.push_back(a[h]) ; 28 sum += a[h] ; 29 } 30 maxx = max(maxx,sum) ; 31 for(int h = 1 ; h <= n ; h++) 32 { 33 if(h < i || h > j) 34 u.push_back(a[h]) ; 35 } 36 sort(v.begin(),v.end()) ; 37 sort(u.begin(),u.end()) ; 38 reverse(u.begin(),u.end()) ; 39 for(int h = 1 ; h <= k && h <= v.size() && h <= u.size() ; h++)//枚举交换次数 40 { 41 if(v[h-1] < u[h-1]) 42 { 43 sum -= v[h-1] ; 44 sum += u[h-1] ; 45 maxx = max(sum,maxx) ; 46 } 47 } 48 } 49 } 50 printf("%d\n",maxx) ; 51 } 52 return 0 ; 53 }
View Code
转载于:https://www.cnblogs.com/luyingfeng/p/3696464.html
Codeforces Round #243 (Div. 2) A~C相关推荐
- Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读
http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...
- Codeforces Round #243 (Div. 1)——Sereja and Squares
题目链接 题意: 给n个点,求能组成的正方形的个数. 四边均平行与坐标轴 大神的分析: 经典题 我们考虑每一种x坐标,显然仅仅有<= sqrt{N}个x坐标出现了> sqrt{N}次,我们 ...
- Codeforces Round #243 (Div. 1)
---恢复内容开始--- A 枚举l,r 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> ...
- Codeforces Round #506 (Div. 3)
Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...
- Codeforces Round #563 (Div. 2)/CF1174
Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...
- 构造 Codeforces Round #302 (Div. 2) B Sea and Islands
题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...
- Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...
- Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...
- Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...
最新文章
- 深入浅出Unix IO模型
- 安卓-控制控件的宽度占屏幕的一半且水平居中显示
- OpenGL ES之着色语言GLSL的使用说明及API
- mysql分组查询和分组过滤
- Cortex‐M3-指令集
- 前端学习(2650):composition组件
- 加密的病历单(信息学奥赛一本通-T1137)
- matlab2c使用c++实现matlab函数系列教程-cumsum函数
- Maven的Snapshot版本与Release版本
- a.out的构成及运行时在内存区域的分配
- MVC案例之删除以及其中遇到的问题,附源代码
- android 音频子系统框架(一)
- Git patch的使用方法和场景
- 网络营销成功案例分析篇:NIKE网络营销案例
- 图解SpringMVC工作流程
- Python知道cos值求角度_机械臂正运动学-DH参数-Python快速实现
- 关于中国地图审图号的说明
- 获取秒懂百科视频地址/获取百度百科视频地址
- html5details标签。
- java双精度怎么比较?误差怎么办?javaDouble类型怎么比较大小?
热门文章
- matlab使用_重磅!哈工大、哈工程无法使用 MATLAB 软件
- 从0开始学习自动化测试框架cypress(五)总结
- java三角形创建子类,A派生出子类B,B派生出子类C,并且在Java源代码中有如下声明: 1.A a0=new 2.A a1 =new 3.A a2=new 问以下哪个说法是正确的?()...
- 蔬菜大棚原理_天津大棚报价大棚的造价、温室大棚
- arch linux rpm格式,如何在ArchLinux上安装RPM包
- 东莞城院c语言上机报告,浙大城市学院c语言上机试题
- gitlab 迁移_无忌过招:手把手教你搭建自己的GitLab库
- php推送系统,php 如何加入即时推送的功能
- linux之fail2ban之预防暴力破解
- mysql数据生产数据分析_基于MySQL玩转SQL数据分析课程 互联网数据分析师-SQL数据分析实战视频教程...