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 ...
随机推荐
- Linode开通新加坡机房:vps速度快,价格不变!
vps服务商linode终于开通了新加坡机房中心,这是linode全球第7个机房,满足日益增长的东南亚市场需求.印度.中国.澳大利亚及周边国家都有很好的用户体验. linode新加坡机房采用思科Cis ...
- Chapter 16_2 继承
类也是对象,所有它们也可以从其他类获得方法.这就是“继承”,可以在Lua中表示: Account = { balance = } function Account:new(o) o = o or {} ...
- 接口post +json +bean
public ReturnBean<DealBean> getMember(String tagtype, String tag) { try { String requestUrl = ...
- B - 小Y上学记——小Y的玩偶
B - 小Y上学记——小Y的玩偶 Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) ...
- HTTP基础知识
HTTP是计算机通过网络进行通信的规则,是一种无状态的协议,不建立持久的连接(客户端向服务器发送请求,web服务器返回响应,接着连接就被关闭了): 一个完整的HTTP请求连接,通常有下面7个步骤: 1 ...
- 移动端日历控件 mobiscroll 的简单使用、参数设置
mobiscroll 在性能方面比较好,可选用多种效果,滑动效果也比较顺畅. 提供样式文件和js文件,直接点击下载,该版本是 mobiscroll 2.13的 官方地址 :https://docs ...
- IOS 第三方库之-MBProgressHUD的使用详解
转自作者: weidfyr http://www.aiuxian.com/article/p-3121607.html 1,MBProgressHUD常用属性和用法Demo - (void)test ...
- Google Developing for Android 学习总结
避免在循环中使用内存 也可理解为在循环中尽可能少创建对象,自定义控件避免在ondraw里面频繁创建paint对象. 尽可能避免内存分配 对象缓存: 常量通过类级别或者静态来进行缓存. 对象池: 同 ...
- 辨别 ShopEX Ecshop
御剑可以识别ShopEX 或者 Ecshop 特征 ShopEX : 蓝色的icon js里有很多Cookie. <link rel="stylesheet" href=&q ...
- form异步无刷新提交,提交后可以显示弹出框,否则弹出框会被刷新不见,使用 preventDefault
出错点:确认按钮上.加onclick事件.每次点击都会追加给form追加on监听方法.累加on方法,重复提交 suppress_exception:true 阻止异常 (百度推送 jdk) 向下按 p ...
The picture corresponds to the first example.