为了能到远方,脚下的每一步都不能少.|

Zac-saodiseng

园龄:2年4个月粉丝:3关注:0

双周赛1

   思维不灵活不会举一反百(反思)

 


也许我们在做自己喜欢的事时总会听见不同的声音
或是支持和鼓励
或是嘲笑和否定
还有一些披着玩笑外衣的讽刺挖苦
不过那都不能成为坚持或放弃的理由
只有热爱可以

 

 写题—>WA—>调题—>还是WA—>重构—>继续WA—>自闭—>水犇犇—>颓—>写题...

Lily

题目链接:题目详情 - 7-1 Lily (pintia.cn)

对于每个花,只有这4种情况:

LLL   _LL   LL_   _L_

分情况讨论就好

 

复制代码
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int N=1010;
 4 int st[N];
 5 //2表示花,1表示不能放猫粮的地方
 6 int main()
 7 {
 8     int n;
 9     cin>>n;
10     string s;
11     cin>>s;
12     for(int i=0;i<s.size();i++)
13     {
14         if(s[i]=='L'&&s[i+1]=='L'&&s[i-1]=='L')st[i]=st[i+1]=st[i-1]=2;
15         else if(s[i]=='L'&&s[i+1]=='L'&&s[i-1]=='.')
16         {
17             st[i]=st[i+1]=2;
18             st[i-1]=1;
19         }
20         else if(s[i]=='L'&&s[i-1]=='L'&&s[i+1]=='.')
21         {
22             st[i]=st[i-1]=2;
23             st[i+1]=1;
24         }
25         else if(s[i]=='L'&&s[i+1]=='.'&&s[i-1]=='.')
26         {
27             st[i]=2;
28             st[i+1]=st[i-1]=1;
29         }
30     }
31     for(int i=0;i<s.size();i++)
32     {
33         if(st[i]==1)cout<<".";
34         else if(st[i]==2)cout<<"L";
35         else cout<<"C";
36     }
37 }
复制代码

 

16进制高精度×高精度

题目链接:题目详情 - 7-2 a * b (pintia.cn)

当x>=10,用switch存一下即可,谁知道考试我这么脑残想不到

复制代码
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 vector<int> mul(vector<int>&A,vector<int>&B)
 4 {
 5     vector<int>C(A.size()+B.size(),0);
 6     for(int i=0;i<A.size();i++)
 7         for(int j=0;j<B.size();j++)
 8             C[i+j]+=A[i]*B[j];
 9     int t=0;
10     for(int i=0;i<C.size();i++)
11     {
12         t+=C[i];
13         C[i]=t%16;
14         t/=16;
15     }
16     while(C.back()==0&&C.size()>1)C.pop_back();
17     return C;
18 }
19 int main()
20 {
21     string a,b;
22     cin>>a>>b;
23     vector<int>A,B;
24     for(int i=a.size()-1;i>=0;i--)
25     {
26         if(a[i]>='0'&& a[i]<='9')A.push_back(a[i]-'0');
27         else
28         {
29             switch(a[i])
30             {
31                 case 'A':A.push_back(10);break;
32                 case 'B':A.push_back(11);break;
33                 case 'C':A.push_back(12);break;
34                 case 'D':A.push_back(13);break;
35                 case 'E':A.push_back(14);break;
36                 case 'F':A.push_back(15);break;
37             }
38         }
39     }
40     for(int i=b.size()-1;i>=0;i--)
41     {
42         if(b[i]>='0'&&b[i]<='9')B.push_back(b[i]-'0');
43         else
44         {
45             switch(b[i])
46             {
47                 case 'A':B.push_back(10);break;
48                 case 'B':B.push_back(11);break;
49                 case 'C':B.push_back(12);break;
50                 case 'D':B.push_back(13);break;
51                 case 'E':B.push_back(14);break;
52                 case 'F':B.push_back(15);break;
53             }
54         }
55     }
56     auto C=mul(A,B);
57     for(int i=C.size()-1;i>=0;i--)
58     {
59         if(C[i]>=0&&C[i]<=9)cout<<C[i];
60         else
61         {
62             switch(C[i])
63             {
64                 case 10:cout<<"A";break;
65                 case 11:cout<<"B";break;
66                 case 12:cout<<"C";break;
67                 case 13:cout<<"D";break;
68                 case 14:cout<<"E";break;
69                 case 15:cout<<"F";break;
70             }
71         }
72     }
73     return 0;
74 }
复制代码

山头狙击战

题目链接:题目详情 - 7-3 山头狙击战 (pintia.cn)

求最大换弹时间,二分,注意在换弹或者士兵没有进入射程之内,大部队在以1m/s行进,所以实际上判断的时候是一个累加的过程

复制代码
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int n,m;
 4 const int N=1e5+10;
 5 int a[N];
 6 bool check(int t)
 7 {
 8     int sum=max(0,a[1]-m);//因为当第一个敌人超出射程的时候,后面部队也在跟随第一个必死的士兵一起行进
 9     for(int i=2;i<=n;i++)
10     {
11         sum+=t;//打死第一个冤枉鬼之后,还有换弹时间,此时后面的士兵也在行进
12         if(a[i]-sum<0)return false;//如果第二个士兵距离-行走的距离<0,说明我们的英雄牺牲了
13     }
14     return true;
15 }
16 int main()
17 {
18     ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
19     cin>>n>>m;
20     for(int i=1;i<=n;i++)
21     {
22         cin>>a[i];
23     }
24     sort(a+1,a+1+n);//二分一定要提前排序!!
25     int l=0,r=1e7;
26     while(l<r)
27     {
28         int mid=l+r+1>>1;
29         if(check(mid))l=mid;
30         else r=mid-1;
31     }
32     cout<<l;
33 }
复制代码

Reversing Linked List

题目链接:题目详情 - 7-4 Reversing Linked List (pintia.cn)

题目
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.
输入格式
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:

1
Address Data Next

where Address is the position of the node, Data is an integer, and Next is the position of the next node.
输出格式
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

输入样例

1
2
3
4
5
6
7
00100 6 4
00000 4 99999
00100 1 12309
68237 6 -1
33218 3 00000
99999 5 68237
12309 2 33218

输出样例

1
2
3
4
5
6
00000 4 33218
33218 3 12309
12309 2 00100
00100 1 99999
99999 5 68237
68237 6 -1

其实就是反转每k个链表,把每个地址压缩到一个数组中,把地址反转即可,最后只遍历该数组即可表示在该地址元素的值

复制代码
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int N=1e5+10;
 4 int e[N],ne[N],idx;
 5 int vis[N];
 6 int head,n,k;
 7 int main()
 8 {
 9     cin>>head>>n>>k;
10     for(int i=0;i<n;i++)
11     {
12         int ad,val,nxt;
13         cin>>ad>>val>>nxt;
14         e[ad]=val,ne[ad]=nxt;
15     }
16     for(int i=head;i!=-1;i=ne[i])
17     {
18         vis[idx++]=i;//把所有地址都压到一个数组里去,并且idx此时是n+1
19     }//因为后续reverse要求左闭右开
20     for(int i=0;i+k<=idx;i+=k)reverse(vis+i,vis+i+k);//反转地址
21     for(int i=0;i<idx;i++)
22     {
23         if(i>=idx-1)printf("%05d %d -1\n",vis[i],e[vis[i]]);
24         else printf("%05d %d %05d\n",vis[i],e[vis[i]],vis[i+1]);
25     }
26 }
复制代码

一元三次方程

题目链接:题目详情 - 7-5 一元三次方程 (pintia.cn)

要保证两个解的大小,因为涉及负号,需要判断大小,如果不满足需要交换

求导,求出两个极点,分成三个单调区间即可

复制代码
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 double a,b,c,d,p,q;
 4 double f(double x)
 5 {
 6     return x*x*x*a+b*x*x+c*x+d;
 7 }
 8 int main()
 9 {
10     int n;
11     cin>>n;
12     for(int i=0;i<n;i++)
13     {
14         cin>>a>>b>>c>>d>>p>>q;
15         double x1=(-2*b-sqrt(4*b*b-12*a*c))/(6*a);
16         double x2=(-2*b+sqrt(4*b*b-12*a*c))/(6*a);
17         if(x1>x2)swap(x1,x2);//a可能小于0,大小就会改变!!!
18         //现在分成了三个单调区间,p~x1,x1~x2,x2~q
19         double l1=p,r1=x1,l2=x1,r2=x2,l3=x2,r3=q;
20         while(r1-l1>1e-8)
21         {
22             double mid=(l1+r1)/2.0;
23             if(f(p)*f(mid)>=0)l1=mid;
24             else r1=mid;
25         }
26         while(r2-l2>1e-8)
27         {
28             double mid=(l2+r2)/2;
29             if(f(x1)*f(mid)>=0)l2=mid;
30             else r2=mid;
31         }
32         while(r3-l3>1e-8)
33         {
34             double mid=(l3+r3)/2;
35             if(f(x2)*f(mid)>0)l3=mid;
36             else r3=mid;
37         }
38         printf("%.6lf %.6lf %.6lf\n",l1,l2,l3);
39     }
40 }
复制代码

 

本文作者:Zac-saodiseng

本文链接:https://www.cnblogs.com/Zac-saodiseng/p/16896726.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Zac-saodiseng  阅读(46)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起