#个人赛第二场解题总结#

来源:互联网 发布:毁童年h知世本子图片 编辑:程序博客网 时间:2024/05/17 04:35
 比赛链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=71617#problem/H

第一题:
H - 水题
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

胖哥自从当上公务员,赢取白富美,走向人生巅峰后,已经懒散到不想出题了,不仅如此,他连题目都懒得看了,现在他只会根据题目第一个单词的长度判定这个题目的难度
如果题目的第一个单词太长(长度大于3),他会说这题太难,不可能想的出来; 如果题目的第一个单词太短(长度不大于3),他会说这题太简单,懒得去想
现在给定一个题目,L想知道胖哥对于这道题会作出什么反应
Input
首先是一个正整数cas,表示有cas组输入,cas<=100
对于每组输入,会给出一行,每行表示一个题目,每个题目只会由大写字母,小写字母或者空格构成,每行的第一个字符一定不会是空格,多个空格可能连续出现,每行最多200个字符
Output
对于每个题目,如果胖哥觉得这题太难,输出"Too hard!",否则输出"Too easy!"


Sample Input
12
If    the   day    is    done
If birds sing no more
If the wind has fiagged tired
Then draw the veil of darkness thick upon me
Even as thou hast wrapt the earth with The coverlet of sleep and tenderly closed
The petals of the drooping lotus at dusk
From the travere
Whose sack of provisions is empty before the voyage is ended
Whose garment is torn and dustladen
Whose strength is exhausted remove shame and poverty
And renew his life like a flower  under
The cover of thy kindly night

Sample Output
Too easy!
Too easy!
Too easy!
Too hard!
Too hard!
Too easy!
Too hard!
Too hard!
Too hard!
Too hard!
Too easy!
Too easy!
水题~~
统计一下第一次出现的空格即可

代码:

#include <math.h>#include <queue>#include <map>#include <set>#include <deque>#include <vector>#include <stack>#include <stdio.h>#include <ctype.h>#include <string.h>#include <stdlib.h>#include <iomanip>#include <iostream>#include <algorithm>using namespace std;#define lowbit(a) a&-a#define Max(a,b) a>b?a:b#define Min(a,b) a>b?b:a#define mem(a,b) memset(a,b,sizeof(a))int dir[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};const double eps = 1e-6;const double Pi = acos(-1.0);static const int inf= ~0U>>2;static const int N=1000;int a[N];char str[N],str2[N];int main(){    int n,m,i,j,a,b,sum;    cin>>n;    getchar();    while(n--)    {        int s=0;        gets(str);        int len=strlen(str);        for(i=0; i<len; i++)        {            if(str[i]!=' ')                s++;                else break;        }        if(s>3)            cout<<"Too hard!"<<endl;        else cout<<"Too easy!"<<endl;    }    return 0;}

第二题:
I - Pangram
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.

Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of characters in the string.

The second line contains the string. The string consists only of uppercase and lowercase Latin letters.

Output
Output "YES", if the string is a pangram and "NO" otherwise.

Sample Input
Input
12
toosmallword
Output
NO
Input
35
TheQuickBrownFoxJumpsOverTheLazyDog
Output
YES
题意:给你一行字符串,如果26个字母每个出现次数不少于一次,则为“pangram”字符串,输出“YES”,否则输出“NO”.
思路:字符串处理,用int数组记录出现不相同字母的次数
代码:
#include <math.h>#include <queue>#include <map>#include <set>#include <deque>#include <vector>#include <stack>#include <stdio.h>#include <ctype.h>#include <string.h>#include <stdlib.h>#include <iomanip>#include <iostream>#include <algorithm>using namespace std;#define lowbit(a) a&-a#define Max(a,b) a>b?a:b#define Min(a,b) a>b?b:a#define mem(a,b) memset(a,b,sizeof(a))int dir[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};const double eps = 1e-6;const double Pi = acos(-1.0);static const int inf= ~0U>>2;static const int N=30010;char str[1010];int main(){    int n;    while(~scanf("%d%s",&n,str))    {        int bb[100];        int flag=0;        mem(bb,0);        int len=strlen(str);        for(int i=0; i<len; i++)        {            if(str[i]>='a')                bb[str[i]-'a']++;            else bb[str[i]-'A']++;        }        for(int i=0; i<26; i++)        {            if(bb[i]) continue;            else flag=1;        }        if(flag) puts("NO");        else puts("YES");    }    return 0;}

第三题:

J - Two Buttons
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
Input
The first and the only line of the input contains two distinct integers n and m (1 ≤ n, m ≤ 104), separated by a space .

Output
Print a single number — the minimum number of times one needs to push the button required to get the number m out of number n.

Sample Input
Input
4 6
Output
2
Input
10 1
Output
9
翻译:屏幕上出现一个数字n,给你两个按钮,每次只能进行一次操作,按下红色按钮数字变为原来的两倍,若按下绿色按钮数字减一,求最小的按法次数使n变为m
PS:
开始用的是bfs,加一个优先队列,求出两种按法次数最少的入队和出队,注意判断一下边界,写完交上去,判题返回“RE”,之后检查了数组是否开太小
,是否没有判重,可能还是不太仔细,哪个细节没有注意,一直re,rrreee!!!,到最后一小时的时候,先放了放,回去想了想C题,一段循环加判断,错了一次,过了C题
最后20分钟左右,回来检查代码,左看右看,实在没发现什么错误,无奈的绝望的心情此刻爆发,重新改大了一点数组,毫不犹豫的再交了一遍,希望奇迹发生,拼点人品啊,
最后真的奇迹发生了,竟然过了,但是感觉很奇怪,之前数组已经调的比较大,而且确实也记得是只稍微改了一下数组,不应该是这个问题,~~(可能也是巧合)~~
最后,比赛完,我让其他人帮我看一下,说可能是判重的地方写的不对,但是感觉判重的地方没多大问题,大家看看有想法的话,欢迎交流~~
PS:此题还有一种 容易理解的暴力模拟,我也是最后才知道,思路是这样的:首先特判一下n和m关系,可以发现,当n大于等于m,只能依次减一,于是答案是n-m
相反,一直除2,能除一直除下去,不能的话就减一。

代码:
BFS+优先队列

#include <math.h>#include <queue>#include <map>#include <set>#include <deque>#include <vector>#include <stack>#include <stdio.h>#include <ctype.h>#include <string.h>#include <stdlib.h>#include <iomanip>#include <iostream>#include <algorithm>using namespace std;#define lowbit(a) a&-a#define Max(a,b) a>b?a:b#define Min(a,b) a>b?b:a#define mem(a,b) memset(a,b,sizeof(a))int dir[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};int n,m,i,j,dp[100005];struct node{    int ste;    int step;} nod;void bfs(){    memset(dp,0,sizeof(dp));    node a,b;    nod.ste=n;    nod.step=0;    queue<node> Q;    while(!Q.empty())        Q.pop();    Q.push(nod);    while(!Q.empty())    {        a=Q.front();        Q.pop();        if(t.ste==m)        {            printf("%d\n",t.step);            return ;        }        int aa=a.ste;        if(dp[aa*2]==0&&aa<=m*2)        {            dp[aa*2]=1;            b.ste=aa*2;            b.step=a.step+1;            Q.push(b);        }        if(aa-1>=0&&dp[aa-1]==0)        {            dp[aa-1]=1;            b.ste=aa-1;            b.step=a.step+1;            Q.push(b);        }    }}int main(){    while(cin>>n>>m)    {        bfs();    }    return 0;}模拟:#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;int main(){    int n,m;    while(cin>>n>>m)    {        if(n>m)            cout<<n-m<<endl;        else {            int sum=0;            while(n!=m){                if(m%2==1){                    sum++;                    m=m+1;                }                m=m/2;                sum++;                if(n>m){                    int a=n-m;                    sum+=a;                    break;                }            }            cout<<sum<<endl;        }    }    return 0;}

第四题:

C - ytaaa
Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Ytaaa作为一名特工执行了无数困难的任务,这一次ytaaa收到命令,需要炸毁敌人的一个工厂,为此ytaaa需要制造一批炸弹以供使用。 Ytaaa使用的这种新型炸弹由若干个炸药组成,每个炸药都有它的威力值,而炸弹的威力值为组成这个炸弹的所有炸药的最大威力差的平方,即(max-min)^2,假设一个炸弹有5个炸药组成,威力分别为5 9 8 2 1,那么它的威力为(9-1)^2=64。现在在炸弹的制造流水线上已经有一行n个炸药,由于时间紧迫,ytaaa并没有时间改变它们的顺序,只能确定他们的分组。作为ytaaa的首席顾问,请你帮助ytaaa确定炸药的分组,使制造出的炸弹拥有最大的威力和。
Input
输入由多组数据组成。第一行为一个正整数n(n<=1000),第二行为n个数,第i个数a[i]为第i个炸药的威力值(0<=a[i]<=1000)。
Output
对于给定的输入,输出一行一个数,为所有炸弹的最大威力和。
Sample Input
6
5 9 8 2 1 6
Sample Output
77

思路:求出0到i之间的区间的最大和最小值,然后一维循环,求出i到j之间的区间的满足最大平方和,注意i从2开始

#include <math.h>#include <queue>#include <map>#include <set>#include <deque>#include <vector>#include <stack>#include <stdio.h>#include <ctype.h>#include <string.h>#include <stdlib.h>#include <iomanip>#include <iostream>#include <algorithm>using namespace std;#define lowbit(a) a&-a#define Max(a,b) a>b?a:b#define Min(a,b) a>b?b:a#define mem(a,b) memset(a,b,sizeof(a))int dir[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};const double eps = 1e-6;const double Pi = acos(-1.0);static const int inf= ~0U>>2;static const int N=30010;int n,m,i,j,aa[2000],bb[200050];int dd[1011][1011],dp[1011];int main(){    while(cin>>n)    {        for(i=1; i<=n; i++)            cin>>aa[i];        mem(dd,0);        mem(dp,0);        int min,max;        for(i=1; i<=n; i++)     //求出0到i之间的区间的最大和最小值        {            for(j=i; j<=n; j++)            {                if(i==j) max=min=aa[i];                if(min>aa[j])                    min=aa[j];                if(max<aa[j])                    max=aa[j];                dd[i][j]=(max-min)*(max-min);            }        }        for(i=2; i<=n; i++)      //一维循环,求出i到j之间的区间的满足最大平方和,注意i从2开始        {            for(j=0; j<=i-1; j++)                dp[i]=Max(dp[i],dp[j]+dd[j+1][i]);        }        cout<<dp[n]<<endl;    }    return 0;}


1 0
原创粉丝点击