题目链接https://qduoj.com/contest/28/problems,密码:qdu1230

E题:

思路:先进行排序,然后去暴力模拟就可以,但可能WA了几次,导致此题没解出来,有点可惜

代码:

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream> using namespace std; int a[3005];
int b[3005];
int main()
{ int n,m;
cin>>n>>m; for(int t=0;t<n;t++)
{
scanf("%d",&a[t]);
}
for(int t=0;t<m;t++)
{
scanf("%d",&b[t]);
}
sort(a,a+n);
sort(b,b+m);
int ma=0,mb=0;
int maxna=0;
int maxnb=0;
for(int t=0;t<n;t++)
{
for(int j=t;j<n;j++)
{
if(ma==5)
{
break;
}
if(a[j]-a[t]<=3)
{
ma++;
}
else
{ ma=0;
break;
}
maxna=max(maxna,ma);
if(j==n-1)
{
ma=0;
} }
}
for(int t=0;t<m;t++)
{ for(int j=t;j<m;j++)
{
if(mb==5)
{
break;
}
if(b[j]-b[t]<=3)
{
mb++;
}
else
{
mb=0;
break;
}
maxnb=max(maxnb,mb);
if(j==m-1)
{
mb=0;
} }
}
cout<<maxna<<endl;
cout<<maxnb<<endl;
if(maxna<=maxnb)
{
cout<<"liangliang\\O..o\\"<<endl;
}
else
{
cout<<"gg/o..O/"<<endl;
}
return 0;
}

F题:

思路:首先对于题目的理解不能有错误,是进行任意轮的命令判断是否能到达,不是就执行那一轮命令,那我们不妨设进行了k轮,然后把每次的坐标变换记录,判断在k轮是否能到达,k的值为(a-每一次的变化量)/一轮的变换量

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream> using namespace std; string str; struct node
{
int x,y;
}pos[1005];
int main()
{
int a,b;
while(cin>>a>>b>>str)
{ int len=str.length();
int x=0,y=0;
int flag=0;
if(x==a&&y==b)
{
cout<<"Yes"<<endl;
continue;
}
for(int t=0;t<len;t++)
{
if(str[t]=='U')
y++;
if(str[t]=='D')
y--;
if(str[t]=='L')
x--;
if(str[t]=='R')
x++;
pos[t].x=x;
pos[t].y=y;
//cout<<pos[t].x<<" "<<pos[t].y<<endl;
}
int k;
for(int t=0;t<len;t++)
{
if(x)
{
k=(a-pos[t].x)/x;
}
else if(y)
{
k=(b-pos[t].y)/y;
}
if(k<0)
k=0;
if(a==k*x+pos[t].x&&b==k*y+pos[t].y)
{
flag=1;
break;
}
}
if(flag)
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
}
return 0;
}

G题:G题看一下数据量就会明白暴力必然超时,那如何去解,我们可以进行分组枚举所有结果,然后,去另一个查找有多少个相等的。我们可以有1,4和2,3两种分法,我们看1,4也十分容易超时,故选用2,3,然后把所有的结果分别放在两个数组里。我们查找的时候用二分进行查找,故要先进行排序,然后我们在较小的里面找较大的,复杂度稍低,然后我们不应该是找是否存在,而应该找存在多少个,所以一个是找左边的下标,一个找右边的下标,这样一减就是个数。还有一个问题,就是开数组的大小,我一开始开的是1e6和1e4,但是会溢出,我就试着跑了下,一个在1e6+1e4左右,另一个没跑,直接就多开大算了。

代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring> using namespace std; int a[10400000];
int b[14005]; int k1,k2;
// 查找第一个相等的元素
int findFirstEqual(int a[], int key) {
int left = 0;
int right = k1 - 1;
while (left <= right) {
int mid = (left + right) / 2;
if (a[mid] >= key) {
right = mid - 1;
}
else {
left = mid + 1;
}
}
if (left < k1 && a[left] == key) {
return left;
} return -1;
}
// 查找最后一个相等的元素
int findLastEqual(int a[], int key) {
int left = 0;
int right = k1- 1;
while (left <= right) {
int mid = (left + right) / 2;
if (a[mid] <= key) {
left = mid + 1;
}
else {
right = mid - 1;
}
}
if (right >= 0 && a[right] == key) {
return right;
} return -1;
}
int main()
{
int T;
cin>>T;
int x1,x2,x3,x4,x5; for(int t=0;t<T;t++)
{
k1=0;
k2=0;
scanf("%d%d%d%d%d",&x1,&x2,&x3,&x4,&x5);
for(int j1=-50;j1<=50;j1++)
{
for(int j2=-50;j2<=50;j2++)
{
for(int j3=-50;j3<=50;j3++)
{
if(j1==0||j2==0||j3==0)
{
continue;
}
a[k1++]=x1*j1*j1*j1+x2*j2*j2*j2+x3*j3*j3*j3; }
}
}
for(int j1=-50;j1<=50;j1++)
{
for(int j2=-50;j2<=50;j2++)
{
if(j1==0||j2==0)
{
continue;
}
b[k2++]=x4*j1*j1*j1+x5*j2*j2*j2;
}
} sort(a,a+k1);
int sum=0;
for(int j=0;j<k2;j++)
{
int l,r;
if(findFirstEqual(a,-b[j])!=-1&&findLastEqual(a,-b[j])!=-1)
{
l=findFirstEqual(a,-b[j]);
r=findLastEqual(a,-b[j]);
sum+=r-l+1;
} }
cout<<sum<<endl;
} return 0;
}

H题:是codeforce一道题的简化版,我的想法是去找原来的串,找原来的串可以通过最长的两个,和最短的两个来确定,通过拼接共有八中情况,由于题目说是有唯一存在,所以必然存在一种是两者相同的,这就是原来的串,找到原来的串,由于数据范围比较小,就可以暴力去找前缀和后缀了,标记一下,最后根据标记来判断前缀和后缀

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm> using namespace std; string str[305];
string s1[305],s2[305];
int vis[305]={0};
int main()
{
int n;
cin>>n;
for(int t=0;t<2*n-2;t++)
{
cin>>str[t];
}
string len1[2],len_n[2];
int k1=0,k2=0;
for(int t=0;t<2*n-2;t++)
{
if(str[t].length()==1)
{
len1[k1++]=str[t];
}
if(str[t].length()==n-1)
{
len_n[k2++]=str[t];
}
}
string stand;
string sss1[4],sss2[4];
//八种情况
sss1[0]=len1[0]+len_n[0];
sss1[1]=len_n[0]+len1[0];
sss1[2]=len1[1]+len_n[0];
sss1[3]=len_n[0]+len1[1];
sss2[0]=len1[0]+len_n[1];
sss2[1]=len_n[1]+len1[0];
sss2[2]=len1[1]+len_n[1];
sss2[3]=len_n[1]+len1[1];
for(int t=0;t<4;t++)
{
for(int j=0;j<4;j++)
{
if(sss1[t]==sss2[j])
{
stand=sss1[t];
}
}
} // cout<<stand<<endl;
string s[205];
s[0]=stand[0];
for(int t=1;t<n-1;t++)
{
s[t]=s[t-1]+stand[t];
}
for(int t=0;t<2*n-2;t++)
{
for(int j=0;j<n-1;j++)
{
if(str[t]==s[j])
{
vis[t]=1;
}
}
}
for(int t=0;t<2*n-2;t++)
{
if(vis[t]==1)
{
cout<<"P";
}
else
{
cout<<"S";
}
}
cout<<endl;
return 0;
}

I题:

思路:狼和草是可以共存的群体,羊和狼草都不能共存,我们就可以分为两大阵营,羊,狼草,然后他们的存在状态总的有两种,一在岸上,一种是在船上,当小的等于d时,如果两大阵营的大的超过船的两倍载重,就会出现混的情况,就会混乱,故当小的等于d时,多的必须小于等于2*d,当小的小于d是时,可以不断的去运多的,就不必考虑多的数量,都可以运

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream> using namespace std; int main()
{ int a,b,c,d;
while(cin>>a>>b>>c>>d)
{
int maxn=max(a+c,b);
int minn=min(a+c,b);
if(minn==d&&maxn<=2*d||(minn<d))
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
} } return 0;
}

QDU第一届程序设计大赛——E到I题解法(非官方题解)的更多相关文章

  1. 2016 "Bird Cup" ICPC7th@ahstu--“波导杯”安徽科技学院第七届程序设计大赛

    "波导杯"安徽科技学院第七届程序设计大赛 Contest - 2016 "Bird Cup" ICPC7th@ahstu Start time:  2016-0 ...

  2. 2016 "Bird Cup" ICPC7th@ahstu--“波导杯”安徽科技学院第七届程序设计大赛

    "波导杯"安徽科技学院第七届程序设计大赛 原文章网页 Contest - 2016 "Bird Cup" ICPC7th@ahstu Start time:   ...

  3. 江西财经大学第一届程序设计竞赛 G题 小Q的口袋校园

    链接:https://www.nowcoder.com/acm/contest/115/G来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...

  4. “九韶杯”河科院程序设计协会第一届程序设计竞赛 D数列重组 next_permutation

    "九韶杯"河科院程序设计协会第一届程序设计竞赛 D数列重组  next_permutation 题目 原题链接: https://ac.nowcoder.com/acm/conte ...

  5. 哈理工软件学院"兆方美迪"杯第六届程序设计大赛【高年级组】--决赛 题解

    比赛链接:http://acm-software.hrbust.edu.cn/contest.php?cid=1082 A.好SB啊真是,还以为lis-数有多少个数不一样. #include < ...

  6. 江西财经大学第一届程序设计竞赛 F题 解方程

    链接:https://www.nowcoder.com/acm/contest/115/F来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...

  7. 江西财经大学第一届程序设计竞赛 H题 求大数的阶乘

    链接:https://www.nowcoder.com/acm/contest/115/H 来源:牛客网 晚上,小P喜欢在寝室里一个个静静的学习或者思考,享受自由自在的单身生活. 他总是能从所学的知识 ...

  8. “东信杯”广西大学第一届程序设计竞赛(同步赛)H

    链接:https://ac.nowcoder.com/acm/contest/283/H来源:牛客网 题目描述 由于临近广西大学建校90周年校庆,西大开始了喜闻乐见的校园修缮工程! 然后问题出现了,西 ...

  9. 江西财经大学第一届程序设计竞赛 I

    链接:https://www.nowcoder.com/acm/contest/115/I来源:牛客网 题目描述 小P和小Q是好朋友,今天他们一起玩一个有趣的游戏. 他们的初始积分都为1,赢的人可以将 ...

随机推荐

  1. BZOJ 1650 [Usaco2006 Dec]River Hopscotch 跳石子:二分

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1650 题意: 数轴上有n个石子,第i个石头的坐标为Di,现在要从0跳到L,每次条都从一个石 ...

  2. POSTGRESQL 导入导出

    安装postgresql yum install postgresql postgresql-server mysql占用端口3306 pgsql是5432 2 导入整个数据库 psql -U pos ...

  3. linux 网络编程 inet_pton & inet_ntop函数

    #include <arpa/inet.h> int inet_pton(int family,const char * strptr,void * addrptr); 返回:--成功, ...

  4. Nginx HTTP Server相关

    一.Nginx安装: 采取手动编译安装 对多种重要的选项进行配置 安装前提:常用工具和库,GCC PCRE(Rewrite模块需要) pcre-devel(源码) zlib zlib-devel(源码 ...

  5. linux 加载raid驱动

    Driver Disk Installation Guide for ARC-11XX/ARC12XX/ARC16XX/18XX RAID Controller on RHEL 5.11 or Cen ...

  6. 浏览器关闭或刷新事件--window.onbeforeunload

    window.onunload=function(){ //不可以阻止浏览器的刷新或者关闭 return false; } window.onbeforeunload=function(){ //可以 ...

  7. zynq基础

    zynq交叉编译环境设置 OpenCV在Zedboard上的移植 ubuntu 下串口调试工具 minicom安装与配置

  8. UDK性能优化

    转自:http://www.cnblogs.com/NEOCSL/p/3320510.html 优化问题有很多内容可讲,涉及林林总总.今天我总结一下优化注意的地方. 1.从AnimTree和Skele ...

  9. [提高班] 2017 Summer Training Day1补题

    题目地址:https://vjudge.net/contest/175939#overview A.数据范围是10^9,所以需要一个巧思路.对于一个数n,如何去判定比它的所有数是否是二进制形式.比n小 ...

  10. why std::stack has separate top() and pop()

    SGI explanation: http://www.sgi.com/tech/stl/stack.html One might wonder why pop() returns void, ins ...