# match1(双周赛)

17 篇文章 0 订阅

## 第一次双周赛

### 1-1 Lily

5
…L…

C.L.C

16 KB

400 ms

64 MB

#### 思路分析

#include<bits/stdc++.h>
using namespace std;
int n;
string s;

int main(){
cin>>n>>s;
for (int i=0; i<n; i++){
if (s[i-1]!='L'&&s[i+1]!='L'&&s[i]!='L')
s[i]='C';
}
cout<<s;
//system("pause");
return 0;
}


### 1-2 a * b

1BF52
1D4B42

332FCA5924

16 KB

400 ms

64 MB

#### 思路分析

1.高精度乘法中，第i位与第j位的乘积在第i+j-1位。
2.输出时前导零的清除。

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+5;
int a[maxn],b[maxn];
int ans[maxn*maxn+10];
void stringtoint(char s1[],char s2[]){
a[0]=strlen(s1);
b[0]=strlen(s2);
for (int i=a[0],j=0; i>0; i--,j++){
if (s1[j]=='A')
a[i]=10;
else if (s1[j]=='B')
a[i]=11;
else if (s1[j]=='C')
a[i]=12;
else if (s1[j]=='D')
a[i]=13;
else if (s1[j]=='E')
a[i]=14;
else if (s1[j]=='F')
a[i]=15;
else
a[i]=s1[j]-'0';
}
for (int i=b[0],j=0; i>0; i--,j++){
if (s2[j]=='A')
b[i]=10;
else if (s2[j]=='B')
b[i]=11;
else if(s2[j]=='C')
b[i]=12;
else if(s2[j]=='D')
b[i]=13;
else if(s2[j]=='E')
b[i]=14;
else if(s2[j]=='F')
b[i]=15;
else
b[i]=s2[j]-'0';
}
return;
}
void multi(){
for (int i=1; i<=a[0]; i++)
for (int j=1; j<=b[0]; j++){
ans[i+j-1]=ans[i+j-1]+a[i]*b[j];
ans[i+j]=ans[i+j]+ans[i+j-1]/16;
ans[i+j-1]=ans[i+j-1]%16;
}
ans[0]=a[0]+b[0];
}
void print_ans(){
while(ans[ans[0]]==0)
ans[0]--;
while (ans[0]>0){
if (ans[ans[0]]==10)
cout<<"A";
else if (ans[ans[0]]==11)
cout<<"B";
else if (ans[ans[0]]==12)
cout<<"C";
else if (ans[ans[0]]==13)
cout<<"D";
else if (ans[ans[0]]==14)
cout<<"E";
else if (ans[ans[0]]==15)
cout<<"F";
else
cout<<ans[ans[0]];
ans[0]--;
}
}
int main(){
char s1[maxn],s2[maxn];
cin>>s1>>s2;
stringtoint(s1,s2);
multi();
print_ans();
//system("pause");
return 0;
}


### 1-3 山头狙击战

6 100
236
120
120
120
120
120

25

16 KB

400 ms

64 MB

#### 思路分析

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int n,m;
int a[maxn];
int doit(int k){
int bg=0;
if (a[1]>m){
bg=a[1]-m;
}
bg+=k;
int num=2;
while (num<=n){
if (bg>a[num]){
return 0;
}
if (a[num]-bg<=m)
bg+=k,num++;
else {
bg+=a[num]-bg-m+k,num++;
}
}
return 1;
}
int main(){
cin>>n>>m;
for (int i=1; i<=n; i++){
cin>>a[i];
}
sort(a+1,a+1+n);
int l=0,r=a[n];
while (l<=r){
int mid=l+r>>1;
if (doit(mid)){
l=mid+1;
}
else {
r=mid-1;
}
//cout<<"l:"<<l<<" "<<"r:"<<r<<endl;
}
cout<<(l+r)/2;
// system("pause");
return 0;
}


#### 题目描述

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 (≤10
5
) 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:

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

#### 思路分析

a数组的下标即为该地址的下标，b数组存储每次需要翻转的k个数。

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
struct node{
int l,r,dat;
}a[maxn];
int b[maxn];

int main(){
string s;
int n,k;
cin>>s>>n>>k;
int fir;
fir=stoi(s);
a[-2].r=fir;
for (int i=1; i<=n; i++){
cin>>s;
}

fir=-2;
for (int i=1; i<=n; i++){
a[a[fir].r].l=fir;
fir=a[fir].r;
}

fir=-2;
int num=0;
int froe=-2,lase=0;
while (fir!=-1){
if (num==k){

for (int i=k; i>=1; i--){
a[b[i]].r=b[i-1];
a[b[i-1]].l=b[i];
}
a[b[k]].l=froe;
a[b[1]].r=lase;
a[froe].r=b[k];
a[lase].l=b[1];
froe=b[1];
num=0;
fir=b[1];
}
else {
fir=a[fir].r;
b[++num]=fir;
lase=a[fir].r;
}
}

fir=-2;

for (int i=1; ; i++){
fir=a[fir].r;
if (a[fir].r==-1){
printf("%05d %d %d\n",fir,a[fir].dat,a[fir].r);
break;
}
else {
printf("%05d %d %05d\n",fir,a[fir].dat,a[fir].r);
}
}
//system("pause");
return 0;
}


（英文题面，助力四级考试）

1.对于双向链表还是不够熟练
2.没有仔细审题，一开始直接用int读取了地址，没有注意前导零的存在
3.debug还是不够熟练

### 1-5 一元三次方程

#### 题目描述

−6），且根范围均在[p,q]之间，你需要解出这个方程的三个根。

1
1.000000 -5.000000 -4.000000 20.000000 -10.000000 10.000000

-2.000000 2.000000 5.000000

#### 思路分析

#include<bits/stdc++.h>
using namespace std;
double a,b,c,d,p,q;
int T;
double multi(double k){
return (a*k*k*k+b*k*k+c*k+d);
}

double midsearch(double l,double r){
double lans=multi(l),rans=multi(r);
if (lans==0){
return l;
}
while (r-l>=1e-6){
double mid=(l+r)/2;
double midans=multi(mid);
if (midans==0){
return mid;
}

if (midans*lans>0){
l=mid;
}
else {
r=mid;
}
}
return (l+r)/2;
}
int main(){
cin>>T;
while (T--){
scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&p,&q);
double a2,b2,c2;
a2=3*a;
b2=2*b;
c2=c;
double l1,r1;
l1=(-1*(b2)-sqrt(b2*b2-4*a2*c2))/(2*a2);
r1=(-1*(b2)+sqrt(b2*b2-4*a2*c2))/(2*a2);
if (l1>r1){
swap(l1,r1);
}
printf("%.6lf %.6lf %.6lf\n",midsearch(p,l1),midsearch(l1,r1),midsearch(r1,q));
//cout<<midsearch(p,l1)<<" "<<midsearch(l1,r1)<<" "<<midsearch(r1,q)<<;
}
//system("pause");
return 0;
}

• 1
点赞
• 0
收藏
觉得还不错? 一键收藏
• 7
评论
11-16
12-16 211
10-27 459
02-08 3万+
11-21 1269
11-18 187
12-12 111
11-15 218

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。