A题

A. Grasshopper And the String
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard 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'.

Input

The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.

Output

Print 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.

Examples
Input
ABABBBACFEYUKOTT
Output
4
Input
AAA
Output
1

遇到从一个元音字母跳向另一个元音字母, 求最大的跳跃间隔. 特别注意全是辅音字母的情况. 暴力水题...

#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. Parade
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard 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.

Input

The 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.

Output

Print 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.

Examples
Input
3
5 6
8 9
10 3
Output
3
Input
2
6 5
5 6
Output
1
Input
6
5 9
1 3
4 8
4 5
23 54
12 32
Output
0
Note

In 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 Sculptor
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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.

Input

The 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.

Output

In 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.

Examples
Input
6
5 5 5
3 2 4
1 4 1
2 1 3
3 2 4
3 3 4
Output
1
1
Input
7
10 7 8
5 10 3
4 2 6
5 5 5
10 2 8
4 2 1
7 7 7
Output
2
1 5
Note

In 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--暴力出奇迹....的更多相关文章

  1. SID1190471 / 烦人的幻灯片 暴力出奇迹 !!!!!!!!!!!!!!!!!!

    PID221 / 烦人的幻灯片 ☆ 提交你的代码 查看讨论和题解 你还木有做过哦 我的状态         查看最后一次评测记录 质量还不能统计出来哦~ 题目评价 质量 无 ★★★★★ ★★★★☆ ★ ...

  2. 紫书 习题 8-2 UVa 1610 (暴力出奇迹)

    这道题我真的想的非常的复杂, 拿草稿纸一直在找规律,推公式, 然后总有一些特殊的情况. 然后就WA了N次.无奈之下看了别人的博客, 然后就惊了.直接暴力枚举两个相邻字符串 里面的所有可能就可以了--真 ...

  3. 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 ...

  4. Codeforces - 570D 离散DFS序 特殊的子树统计 (暴力出奇迹)

    题意:给定一棵树,树上每个节点有对应的字符,多次询问在\(u\)子树的深度为\(d\)的所有节点上的字符任意组合能否凑成一个回文串 把dfs序存储在一个二维线性表中,一个维度记录字符另一个维度记录深度 ...

  5. Post Lamps CodeForces - 990E(暴力出奇迹?)

    题意: 在一个从0开始的连续区间上  放置几个小区间,使得这些小区间覆盖整个大区间,不同长度的小区间有不同的花费,其中有m个点,小区间的左端点不能放在这些点上 解析: 显然如果0是这m点中的一个 则无 ...

  6. Prime Matrix(暴力出奇迹)

    Description You've got an n × m matrix. The matrix consists of integers. In one move, you can apply ...

  7. 51nod——1285 山峰和分段(暴力出奇迹)

    要求每段的点数都一样,因此分的段数cnt肯定是n的因子,要求每段都有山峰,因此cnt肯定小于等于山峰数量.分段的宽度d=n/cnt,对山峰数量做一个前缀和,检查一下每一段的山峰数量是否没有增加即可. ...

  8. 【杂】暴力出奇迹,lz水数据

    做了个填涂颜色的题qwq 洛谷上的qwq,然后我就把这道题水过去了qwq(显然这是不对的,我们不能水数据qwq)当然我本身是80分的qwq end-

  9. HDU4587--TWO NODES(无向图割点,暴力出奇迹)这是我见过的时间最长的题。。。

    TWO NODES Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total ...

  10. Manthan, Codefest 16 H. Fibonacci-ish II 大力出奇迹 莫队 线段树 矩阵

    H. Fibonacci-ish II 题目连接: http://codeforces.com/contest/633/problem/H Description Yash is finally ti ...

随机推荐

  1. 我使用的Bash脚本模板

    在Linux环境下(包括在相应的模拟环境,如Windows中的Cygwin)工作的时间久了,就会慢慢积累出一些自己写的小脚本程序,用于加速日常的操作与工作流程,如自动挂载与卸载U盘,映射网络驱动器,数 ...

  2. Python 学习笔记12

    不积跬步,无以至千里.不积小流,无以成江河. 当我觉得沮丧.绝望的时候,就疯狂的敲代码,这样会好受一点. 今天和昨天敲了两天的小程序,算是对python的具体语法规则有个初步的手熟. http://w ...

  3. 进入BIOS SHELL DUMP 命令

    LINUX系统 进入SHELL 输入命令 fs1: or fs0: 就进入了U盘目录 然后输入 ACPIRW.efi  -d -s dsdt.bat 就会产生结果到U盘 ——————————————— ...

  4. 移动前端不得不了解的HTML5 head 头标签(中上篇)

    Meta 标签 meta标签是HTML中head头部的一个辅助性标签,它位于HTML文档头部的 <head> 和 <title> 标记之间,它提供用户不可见的信息.虽然这部分信 ...

  5. HTML+CSS D09 定位

    1.定位 (1)相对定位 如果对一个元素进行相对定位,它将出现在它所在的位置上.然后,可以通过设置垂直或水平位置,让这个元素“相对于”它的起点进行移动. #box_relative {  positi ...

  6. 把ResultSet对象转变成List对象

    private static List<Map<String, Object>> convertRS2List(ResultSet rs) throws SQLExceptio ...

  7. HDU 3499 Flight spfa+dp

    Flight Time Limit : 20000/10000ms (Java/Other)   Memory Limit : 65535/65535K (Java/Other) Total Subm ...

  8. 如何禁用电脑USB接口

    方法一,BIOS设置法 重新启动计算机,在开机过程中,点击键盘上的“Delete”键,进入BIOS设置界面,选择“Integrated Peripherals”选项,展开后将“USB 1.1 Cont ...

  9. STM32F446 OTG_FS_DP/DM调试

    之前项目用STM32F207,现在升级到用STM32F446处理器,用到USB的OTG_FS模式接法: 1.USB只连接了DP/DM 2.DP需上拉1.5K的电阻到3.3V 3.PA9(VBUS) 和 ...

  10. C# WebBrowser函数互相调用

    在使用C#开发winform程序过程中,我们经常会碰到嵌入了一个WebBrowser的浏览器控件.很多时候,我们需要在程序里控制网页的显示方式,或者调用网页当中的某个JS函数,反过来,也有可能网页也需 ...