7-1 Lily
分数 300
作者 neuqAcmClub
单位 东北大学秦皇岛分校
百合花(Lily)是一种美丽的花。她通常一年只开一次花,所以如果你看到百合花盛开,它会非常珍贵。然而,她对猫有剧毒,所以你必须注意让好奇的猫远离可爱的百合花。
你有n个网格的土壤土地排成一行,从1到n,其中一些是百合花。我们不想伤害百合,也不想伤害猫。你可以在网格上放一些猫粮,但对于任何有猫粮的网格i,在区域[i−1,i+1]不得含有百合花。你喜欢猫和百合,所以你想最大限度地增加有猫粮的格子。
设计满足上述要求的计划。
输入格式:
有一个整数n(1≤n≤1000)表示网格的数量。
第二行包含仅由“L”和“.”组成的字符串R,表示有和没有百合花的格子。
输出格式:
输出包含一行,字符串R′仅由“L”、“”组成和“C”,其中“C”表示在满足上述要求的同时分配给R中空网格的猫粮。
输入样例:
在这里给出一组输入。例如:
5
..L..
输出样例:
在这里给出相应的输出。例如:
C.L.C
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
第一题只要给每个有百合花的格子打上标记,后面再遍历一遍,左右都没有百合花就输出猫粮“C”,否则输出“.” 然后第一个和最后一个单独拎出来判断就行了。
#include <bits/stdc++.h>
using namespace std;
int judge[1010];
int main()
{
int n;
string s;
cin>>n>>s;
int l=s.length();
for(int i=0;i<=l-1;i++)
{
if(s[i]=='L')judge[i]=1;//给有百合花的格子打上标记
}
for(int i=0;i<=l-1;i++)
{
if(judge[i]==1){cout<<'L';continue;}//是百合花就直接输出
else
{
if(i==0)//第一个格子和最后一个格子特殊考虑
{
if(s[1]!='L')cout<<'C';
else cout<<'.';
}
else if(i==l-1)
{
if(s[l-2]!='L')cout<<'C';
else cout<<'.';
}
else //正常情况下看左右两个格子有没有百合花,没有就输出猫粮“C”
{
if(s[i-1]!='L'&&s[i+1]!='L')cout<<'C';
else cout<<'.';
}
}
}
cout<<endl;
return 0;
}
7-2 a * b
分数 300
作者 neuqAcmClub
单位 东北大学秦皇岛分校
给出两个不超过1000位的十六进制数a,b。
求a∗b的值
输入格式:
输入共两行,两个十六进制的数
输出格式:
输出一行,表示a∗b
输入样例:
在这里给出一组输入。例如:
1BF52
1D4B42
输出样例:
在这里给出相应的输出。例如:
332FCA5924
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
其实就是把原来的高精度乘高精度模板套一遍,把权值换成了16.。。
然后注意消除前置0就好。。
#include <bits/stdc++.h>
using namespace std;
string str1,str2;
int a[1010],b[1010],c[3000];
int main()
{
cin>>str1>>str2;
int l1=str1.length(),l2=str2.length();
for(int i=l1;i>=0;i--)//读入数据
{
if(str1[i]>='A'&&str1[i]<='F')a[l1-i]=str1[i]-'A'+10;
else if(str1[i]>='0'&&str1[i]<='9')a[l1-i]=str1[i]-'0';
}
for(int i=l2;i>=0;i--)
{
if(str2[i]>='A'&&str2[i]<='F')b[l2-i]=str2[i]-'A'+10;
else if(str2[i]>='0'&&str2[i]<='9')b[l2-i]=str2[i]-'0';
}
int x=l1+l2;
for(int i=0;i<=l1;i++)
{
int t=0,temp=0;
for(int j=0;j<=l2;j++)
{//其实就是标准高精度乘法模板,只不过把权重换成了16
temp=a[i]*b[j]+t;
t=(c[i+j]+temp)/16;
c[i+j]=(c[i+j]+temp)%16;
if(j==l2&&t!=0)
{
c[i+j+1]=c[i+j+1]+t;
if(i==l1)x++;
}
}
}
int f=0;
if(c[0]==0)
{
for(int j=0;j<=x;j++)
{
if(c[j]!=0){f=j;break;}//用来消除前置0
}
}
for(int i=x;i>=f;i--)
{
if(c[i]>=10&&c[i]<=15)printf("%c",c[i]+55);//数字和字母用不同方法输出
else cout<<c[i];
}
cout<<endl;
return 0;
}
7-3 山头狙击战
分数 300
作者 neuqAcmClub
单位 东北大学秦皇岛分校
题目描述
小明为了掩护大部队,单枪匹马同敌人周旋,后来被敌人包围在某山头……等等,为什么怎么听怎么像狼牙山五壮士!不过不用着急,这次小明携带了足够的弹药,完全可以将涌上来的敌人一个一个干掉。小明是个神枪手,只要他的枪膛中有子弹,他就能将在他射程m(用从敌人位置到山头的直线距离算)以内的一个敌人瞬间射杀。但如果在射程内没有敌人,出于节约子弹考虑和面子问题,小明会等待敌人靠近然后射击。
正当小明为自己的强大而自我膨胀时,他忽然发现了一个致命的失误:他携带的枪是单发枪,每射出一发子弹都必须花k秒钟的时间装子弹。而凶残的敌人才不会花时间等你换子弹呢。他们始终在以1m/s的速度接近山头。而如果在一个敌人到达山头时小明无法将他击毙,那么我们可怜的小明就将牺牲在敌人的刺刀下。现在小明用心灵感应向你发出求助:要保住自己的性命并且歼灭所有敌人,小明最多只能用多少时间给枪装上一发子弹?
说明:假设一开始小明的枪中就有一发子弹,并且一旦确定一个装弹时间,小明始终会用这个时间完成子弹的装卸。希望你能帮助小明脱离险境。
输入格式
每组输入数据,第一行有两个整数n和m,(2≤n≤100,000; 1≤m≤10,000,000)n代表敌人个数,m代表小明的射程。
接下来有n行,每行一个整数mi,(1≤mi≤10,000,000),代表每个敌人一开始相对山头的距离(单位为米)。
输出格式
每组输出数据仅有一个整数,代表小明的换弹时间(单位为秒)。
样例输入
6 100
236
120
120
120
120
120
样例输出
25
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
周赛就是在这里卡了。。。原因是一开始把数组mi开在全局了,然后因为我是每次都移动敌人的距离,所以check用一遍之后mi里面的初值已经变了,导致下一次check已经没有意义了。后来想了个不用修改mi数组值的办法吧,比原来的写法简洁非常非常多,唉,好后悔!
check想明白就是个标准的二分答案。。。
#include <bits/stdc++.h>
using namespace std;
int n,m,mi[100010];
bool check(int k)
{
int t=0;
if(mi[1]>m)t=mi[1]-m;//第一个敌人在射程外,敌人前进时间也有考虑
for(int i=2;i<=n;i++)
{
t+=k;//换弹的时候敌人都在前进
if(mi[i]-t>m)//在射程外,又给了敌人一些前进的时间
{
t=t+mi[i]-t-m;
}
if(t>mi[i])return 0;//如果所用时间大于敌人距离,说明已经来不及了
}
return 1;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>mi[i];
}
sort(mi+1,mi+n+1);//把每个敌人的距离由近到远排序
int l=0,r=100000000;
while(l<r)
{
int mid=(l+r+1)/2;
if(check(mid))l=mid;
else r=mid-1;
}
cout<<l<<endl;
return 0;
}
7-4 Reversing Linked List
分数 300
作者 陈越
单位 浙江大学
Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K=3, then you must output 3→2→1→6→5→4; if K=4, you must output 4→3→2→1→5→6.
Input Specification:
Each input file contains one test case. For each case, the first line contains the address of the first node, a positive N (≤105) which is the total number of nodes, and a positive K (≤N) which is the length of the sublist to be reversed. The address of a node is a 5-digit nonnegative integer, and NULL is represented by -1.
Then N lines follow, each describes a node in the format:
Address Data Next
where Address
is the position of the node, Data
is an integer, and Next
is the position of the next node.
Output Specification:
For each case, output the resulting ordered linked list. Each node occupies a line, and is printed in the same format as in the input.
Sample Input:
00100 6 4
00000 4 99999
00100 1 12309
68237 6 -1
33218 3 00000
99999 5 68237
12309 2 33218
Sample Output:
00000 4 33218
33218 3 12309
12309 2 00100
00100 1 99999
99999 5 68237
68237 6 -1
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
周赛的时候这道题看都不配看
后面重现的时候再做发现这题坑是真的巨多啊!本身英文就不好理解,后来看了题解才知道是每过K个节点就要反转,是真坑啊。。
有些点是不在链表上的,所以。。必须要开个vector来存链表。然后遍历vector
#include <bits/stdc++.h>
using namespace std;
int K,N,a,b,c,head;
typedef struct
{
int data;
int next;
}Node;
Node ne[100005];
vector<int> p;
int main()
{
cin>>head>>N>>K;
for(int i=1;i<=N;i++)
{
cin>>a>>b>>c;//按顺序存入每个点的地址和下一个点的地址
ne[a].data=b;
ne[a].next=c;
}
while(head!=-1)//把链表顺次存入vector
{
p.push_back(head);
head=ne[head].next;
}
int l=p.size();
for(int i=0;i<l-l%K;i=i+K)reverse(p.begin()+i,p.begin()+i+K);//最最坑的点,每K个点就需要反转一次
for(int i=0;i<l-1;i++)
{
printf("%05d %d %05d\n",p[i],ne[p[i]].data,p[i+1]);
}
printf("%05d %d -1",p[l-1],ne[p[l-1]].data);
return 0;
}
7-5 一元三次方程
分数 300
作者 neuqAcmClub
单位 东北大学秦皇岛分校
给定一个形如ax3+bx2+cx+d=0的一元三次方程。
已知该方程有三个不同的实数根(根与根之差的绝对值≥10−6),且根范围均在[p,q]之间,你需要解出这个方程的三个根。
输入格式:
第一行一个整数T(1≤T≤1000),表示有T组数据
接下来T行,每行6个实数,分别表示a,b,c,d,p,q
数据保证:−102≤p,q≤102,且对于∀x∈[p,q],−106≤f(x)≤106
输出格式:
输出三个实数,表示方程的三个解。
你的答案可以以任意顺序输出。
一个答案被认为是正确的,当且仅当其与标准答案的绝对误差不超过10−6
输入样例:
在这里给出一组输入。例如:
1
1.000000 -5.000000 -4.000000 20.000000 -10.000000 10.000000
输出样例:
在这里给出相应的输出。例如:
-2.000000 2.000000 5.000000
提示1:
样例所给方程的图像如下:
提示2:
对于方程:ax2+bx+c=0(Δ=b2−4ac≥0),它的两个根分别为:x1=2a−b−Δ,x2=2a−b+Δ
代码长度限制
16 KB
时间限制
500 ms
内存限制
128 MB
这题也很折腾啊。首先要把三次方程求导找到两个极值点,从而得到三段分别包含三个零点的区间,然后在做三次浮点数二分找到三个零点。。
关键在a的正负决定了两个极值点的次序和后来二分时候的判断标准。。
a>0就是先增后减再增
反之先减后增再减
具体看代码。。。
#include <bits/stdc++.h>
using namespace std;
int T;
double a,b,c,d,p,q,x1,x2,mid,l,r;
bool check(double mid)
{
if(a*mid*mid*mid+b*mid*mid+c*mid+d>=0)return 1;
else return 0;
}
int main()
{
cin>>T;
for(int i=1;i<=T;i++)
{
cin>>a>>b>>c>>d>>p>>q;
if(a>0)//一元二次方程求根公式
{
x1=(-2*b-sqrt(4*pow(b,2)-12*a*c))/(6*a);
x2=(-2*b+sqrt(4*pow(b,2)-12*a*c))/(6*a);
}
else//两根次序与a的正负有关
{
x2=(-2*b-sqrt(4*pow(b,2)-12*a*c))/(6*a);
x1=(-2*b+sqrt(4*pow(b,2)-12*a*c))/(6*a);
}
if(a>0)
{
l=-100,r=x1;
while(r-l>0.000000000001)
{
mid=(l+r)/2;
if(check(mid))r=mid;
else l=mid;
}
cout<<fixed<<setprecision(9)<<l<<' ';
l=x1,r=x2;
while(r-l>0.000000000001)
{
mid=(l+r)/2;
if(check(mid))l=mid;
else r=mid;
}
cout<<fixed<<setprecision(9)<<l<<' ';
l=x2,r=100;
while(r-l>0.000000000001)
{
mid=(l+r)/2;
if(check(mid))r=mid;
else l=mid;
}
cout<<fixed<<setprecision(9)<<l<<endl;
}
else
{
l=-100,r=x1;
while(r-l>0.000000000001)
{
mid=(l+r)/2;
if(check(mid))l=mid;
else r=mid;
}
cout<<fixed<<setprecision(9)<<l<<' ';
l=x1,r=x2;
while(r-l>0.000000000001)
{
mid=(l+r)/2;
if(check(mid))r=mid;
else l=mid;
}
cout<<fixed<<setprecision(9)<<l<<' ';
l=x2,r=100;
while(r-l>0.000000000001)
{
mid=(l+r)/2;
if(check(mid))l=mid;
else r=mid;
}
cout<<fixed<<setprecision(9)<<l<<endl;
}
}
return 0;
}
总结这次周赛,,真的还需要努力啊。。加油吧!