CodeForces#378--A, B , D--暴力出奇迹....
A题
A. Grasshopper And the Stringtime limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump.
Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability.
The picture corresponds to the first example.
The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'.
InputThe first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.
OutputPrint single integer a — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.
ExamplesInputABABBBACFEYUKOTTOutput4InputAAAOutput1
遇到从一个元音字母跳向另一个元音字母, 求最大的跳跃间隔. 特别注意全是辅音字母的情况. 暴力水题...
#include<bits/stdc++.h>
using namespace std;
char a[]={'A','E','I','O','U','Y'};
bool ok(char c)
{
for(int i=;i<;i++){
if(c==a[i])
return ;
}
return ;
}
int main()
{
//freopen("data.in","r",stdin);
string str;
int flag=;
int res=-;
while(cin>>str){
res=-;
flag=;
for(int i=;i<str.length();i++){
flag++;
if(ok(str[i])){
// cout<<11111111<<endl;
res=max(flag,res);
flag=;
}
}
res=max(flag+,res);
cout<<res<<endl;
str.clear();
}
}
B题
B. Paradetime limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits begin to march, so it is only important how many soldiers march in step.
There will be n columns participating in the parade, the i-th column consists of li soldiers, who start to march from left leg, and ri soldiers, who start to march from right leg.
The beauty of the parade is calculated by the following formula: if L is the total number of soldiers on the parade who start to march from the left leg, and R is the total number of soldiers on the parade who start to march from the right leg, so the beauty will equal |L - R|.
No more than once you can choose one column and tell all the soldiers in this column to switch starting leg, i.e. everyone in this columns who starts the march from left leg will now start it from right leg, and vice versa. Formally, you can pick no more than one index i and swap values li and ri.
Find the index of the column, such that switching the starting leg for soldiers in it will maximize the the beauty of the parade, or determine, that no such operation can increase the current beauty.
InputThe first line contains single integer n (1 ≤ n ≤ 105) — the number of columns.
The next n lines contain the pairs of integers li and ri (1 ≤ li, ri ≤ 500) — the number of soldiers in the i-th column which start to march from the left or the right leg respectively.
OutputPrint single integer k — the number of the column in which soldiers need to change the leg from which they start to march, or 0 if the maximum beauty is already reached.
Consider that columns are numbered from 1 to n in the order they are given in the input data.
If there are several answers, print any of them.
ExamplesInput3
5 6
8 9
10 3Output3Input2
6 5
5 6Output1Input6
5 9
1 3
4 8
4 5
23 54
12 32Output0NoteIn the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal 5 + 8 + 10 = 23, and from the right leg — 6 + 9 + 3 = 18. In this case the beauty of the parade will equal |23 - 18| = 5.
If you give the order to change the leg to the third column, so the number of soldiers, who march from the left leg, will equal 5 + 8 + 3 = 16, and who march from the right leg — 6 + 9 + 10 = 25. In this case the beauty equals |16 - 25| = 9.
It is impossible to reach greater beauty by giving another orders. Thus, the maximum beauty that can be achieved is 9.
目标是使左边的和与右边的和差值最大, 可以交换不多于一行的左值与右值. 一开始我还想去找规律, 没想到暴力处理竟然不超时就过了...汗....
#include<bits/stdc++.h>
using namespace std;
const int MAXN=;
int l[MAXN];
int r[MAXN];
int suml,sumr;
int main()
{
//freopen("data.in","r",stdin);
int n;
int flag;
int cc;
while(cin>>n){
suml=sumr=;
for(int i=;i<=n;i++){
cin>>l[i]>>r[i];
suml+=l[i];
sumr+=r[i];
}
int res=abs(suml-sumr);
flag=;
int ll=suml;
int rr=sumr;
for(int i=;i<=n;i++){
cc=abs(l[i]-r[i]);
if(l[i]<r[i]){
ll+=cc;
rr-=cc;
}
else{
ll-=cc;
rr+=cc;
}
if(res<abs(ll-rr)){
res=abs(ll-rr);
flag=i;
}
ll=suml;
rr=sumr;
}
cout<<flag<<endl;
}
}
D题
D. Kostya the Sculptortime limit per test3 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere.
Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya.
If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way.
Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar.
InputThe first line contains the integer n (1 ≤ n ≤ 105).
n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≤ ai, bi, ci ≤ 109) — the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones.
OutputIn the first line print k (1 ≤ k ≤ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n — the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data.
You can print the stones in arbitrary order. If there are several answers print any of them.
ExamplesInput6
5 5 5
3 2 4
1 4 1
2 1 3
3 2 4
3 3 4Output1
1Input7
10 7 8
5 10 3
4 2 6
5 5 5
10 2 8
4 2 1
7 7 7Output2
1 5NoteIn the first example we can connect the pairs of stones:
- 2 and 4, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1
- 2 and 5, the size of the parallelepiped: 3 × 2 × 8 or 6 × 2 × 4 or 3 × 4 × 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively.
- 2 and 6, the size of the parallelepiped: 3 × 5 × 4, the radius of the inscribed sphere 1.5
- 4 and 5, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1
- 5 and 6, the size of the parallelepiped: 3 × 4 × 5, the radius of the inscribed sphere 1.5
Or take only one stone:
- 1 the size of the parallelepiped: 5 × 5 × 5, the radius of the inscribed sphere 2.5
- 2 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1
- 3 the size of the parallelepiped: 1 × 4 × 1, the radius of the inscribed sphere 0.5
- 4 the size of the parallelepiped: 2 × 1 × 3, the radius of the inscribed sphere 0.5
- 5 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1
- 6 the size of the parallelepiped: 3 × 3 × 4, the radius of the inscribed sphere 1.5
It is most profitable to take only the first stone.
给出n块方块, 拿出1块或2块, 使其组合之后内切圆最大(最小的边最大),我的处理方法是将每块方块处理为3块,记录一下每个方块原本的序号, 然后排序, 从而可以和当前位置匹配的方块一定在当前位置附近, 暴力枚举即可.
然后今天早上看到了一个特别巧妙的处理方法, 不用将1块处理为3块:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
struct node{
int a,b,c,lab;
}e[];
bool cmp(node a,node b){
if(a.c==b.c&&a.b==b.b)return a.a<b.a;
if(a.c==b.c)return a.b<b.b;
return a.c<b.c;
}
bool pick(int a,int b){
if(e[a].c==e[b].c&&e[a].b==e[b].b) return ;
return ;
}
int main(){
int n,i,j,x,y,z,ans=,k=,t,ans1,ans2,dd;
scanf("%d",&n);
for(i=;i<=n;i++){
scanf("%d%d%d",&x,&y,&z);
int s1=min(x,min(y,z)),s2=max(x,max(y,z));
if(s1>ans){
ans=s1;
dd=i;
t=;
}
e[i].a=s1;
e[i].b=x+y+z-s1-s2;
e[i].c=s2;
e[i].lab=i;
}
sort(e+,e++n,cmp);
for(i=n;i>=;i--){
if(pick(i-,i)){
int ss=min(e[i].a+e[i-].a,min(e[i].b,e[i].c));
if(ss>ans){
t=;
ans=ss;
ans2=e[i].lab;
ans1=e[i-].lab;
}
}
}
printf("%d\n",t);
if(t==)printf("%d\n",dd);
else printf("%d %d\n",ans1,ans2);
return ;
}
CodeForces#378--A, B , D--暴力出奇迹....的更多相关文章
- SID1190471 / 烦人的幻灯片 暴力出奇迹 !!!!!!!!!!!!!!!!!!
PID221 / 烦人的幻灯片 ☆ 提交你的代码 查看讨论和题解 你还木有做过哦 我的状态 查看最后一次评测记录 质量还不能统计出来哦~ 题目评价 质量 无 ★★★★★ ★★★★☆ ★ ...
- 紫书 习题 8-2 UVa 1610 (暴力出奇迹)
这道题我真的想的非常的复杂, 拿草稿纸一直在找规律,推公式, 然后总有一些特殊的情况. 然后就WA了N次.无奈之下看了别人的博客, 然后就惊了.直接暴力枚举两个相邻字符串 里面的所有可能就可以了--真 ...
- Codeforces Round VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM 暴力出奇迹!
VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM Time Lim ...
- Codeforces - 570D 离散DFS序 特殊的子树统计 (暴力出奇迹)
题意:给定一棵树,树上每个节点有对应的字符,多次询问在\(u\)子树的深度为\(d\)的所有节点上的字符任意组合能否凑成一个回文串 把dfs序存储在一个二维线性表中,一个维度记录字符另一个维度记录深度 ...
- Post Lamps CodeForces - 990E(暴力出奇迹?)
题意: 在一个从0开始的连续区间上 放置几个小区间,使得这些小区间覆盖整个大区间,不同长度的小区间有不同的花费,其中有m个点,小区间的左端点不能放在这些点上 解析: 显然如果0是这m点中的一个 则无 ...
- Prime Matrix(暴力出奇迹)
Description You've got an n × m matrix. The matrix consists of integers. In one move, you can apply ...
- 51nod——1285 山峰和分段(暴力出奇迹)
要求每段的点数都一样,因此分的段数cnt肯定是n的因子,要求每段都有山峰,因此cnt肯定小于等于山峰数量.分段的宽度d=n/cnt,对山峰数量做一个前缀和,检查一下每一段的山峰数量是否没有增加即可. ...
- 【杂】暴力出奇迹,lz水数据
做了个填涂颜色的题qwq 洛谷上的qwq,然后我就把这道题水过去了qwq(显然这是不对的,我们不能水数据qwq)当然我本身是80分的qwq end-
- HDU4587--TWO NODES(无向图割点,暴力出奇迹)这是我见过的时间最长的题。。。
TWO NODES Time Limit: 24000/12000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total ...
- Manthan, Codefest 16 H. Fibonacci-ish II 大力出奇迹 莫队 线段树 矩阵
H. Fibonacci-ish II 题目连接: http://codeforces.com/contest/633/problem/H Description Yash is finally ti ...
随机推荐
- 通过RVM安装Ruby失败
第一次安装失败是由于Homebrew一直安装不成功,遂去http://brew.sh/index_zh-cn.html官网 通过 /usr/bin/ruby -e "$(curl -fsSL ...
- redis高级实用特性(2)
事务处理: redis对事务的支持目前还是比较简单,redis只能保证一个 client发起事务中的命令可以连续执行,而中间不会插入其他 client的命令,当一个client 在一个连接中发出mul ...
- 如何成为出色的IT项目经理:成功的五个关键因素
“出色”的IT 项目经理的定义不是一成不变的.随着经济和商业因素的改变,项目经理的角色进行调整以适应新的需求,迎接新的挑战. 除了一般的困惑之外,还有一种看法就是,在组织中,不同的人对于项目经理的看法 ...
- The type java.util.Map$Entry cannot be resolved. It is indirectly referenced from required .class files
JDK版本的问题. 解决方法: 原来jdk1.8不向下兼容,用回1.6的就可以了. 下图有三个jdk,前两个自己装的,第三个MyEclipse自带的.
- 一些常见warning的原因和解决方法
在入职三周后,终于赶齐了接手项目落下两个月的项目,有了一些自己的空闲时间对项目进行整理.主要整理包括类目的整合,从原来一个系统文件夹下几百个文件整改为以MVC设计思想为原则的分文件夹整理类目,井然有序 ...
- ASP.NET弹出提示点击确定之后再跳转页面的方法
//ASP.NET弹出提示点击确定之后再跳转页面的方法 //弹出了提示并且通过location.href转到了DeskTop.aspx页面 Response.Write("<scrip ...
- 第三十五节,json数据类型转换字符串模块
在使用json模块时需要先 import json 引入模块 json.dumps()模块函数 功能:将Python数据类型转换成字符串[有参] 使用方法:json.dumps(要转换的数据类型变量) ...
- js 学习总结
new array()[] []表示数组new object(){} {}表示对象 JavaScript 对象 对象由花括号分隔.在括号内部,对象的属性以名称和值对的形式 (name : value) ...
- 递归解析任意层的json
package com.sun.test; import java.util.Iterator; import net.sf.json.JSONArray;import net.sf.json.JSO ...
- 打印出最后执行的mysql 语句
db.php 文件中添加 public function getlastsql(){ return $this->sql; } 入口文件中添加,公共方法 function getlastsql( ...