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 ...
随机推荐
- 第三次冲刺spring会议(第一次会议)
[例会时间]2014/5/20 21:15 [例会地点]9#446 [例会形式]轮流发言 [例会主持]马翔 [例会记录]兰梦 小组成员:兰梦 ,马翔,李金吉,赵天,胡佳
- 自定义函数动态执行SQL语句
Oracle 动态SQL有两种写法:用 DBMS_SQL 或 execute immediate,建议使用后者. DDL 和 DML Sql代码 收藏代码 /*** DDL ***/ begin EX ...
- great C++ socket library
NETLINK: http://netlinksockets.sourceforge.net/index.html
- visible绑定(The "visible" binding)
对visible进行绑定可以控制元素的显示和隐藏. 示例: <div data-bind="visible: shouldShowMessage"> You will ...
- 通过httplib2 探索的学习的最佳方式
在工作中需要对一个视频点播两百次,使其成为热门视频,才能对其p2p情况进行测试.虽然可以手动点播两百次,但是利用python发送200次post请求,能减少很多的工作量.该发送请求的方法用到了http ...
- Spring Timer实现
定时器:继承java.util.TimerTask类实现run方法 package com.zbb.framework.util.timer; import java.util.TimerTask; ...
- subnetting and the subnet mask
原文:https://www.techopedia.com/6/28587/internet/8-steps-to-understanding-ip-subnetting/5 Step 4 - Sub ...
- JPA 系列教程15-继承-一个表-SINGLE_TABLE
继承映射策略 一个类继承结构一个表的策略,最终只生成一个表,这是继承映射的默认策略. 举例 如果实体类Teacher继承实体类Person,实体类Student也继承自实体Person,那么只会映射成 ...
- OpenJDK和JDK的区别
作者:Aloys寒风链接:https://www.zhihu.com/question/19646618/answer/40621705来源:知乎著作权归作者所有,转载请联系作者获得授权. 使用过LI ...
- applicationContext.xml 配置(扫描)
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
The picture corresponds to the first example.