马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
L - Stella
题目泉源:L - Stella
解题思路
签到题,因为给出的字母不是按次序,可以存起来赋其值,然后在比力。
代码实现
- #include<bits/stdc++.h>
- #define int long long
- #define endl '\n'
- #define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
- using namespace std;
- const int N=1e5+5;
- void solve()
- {
- map<char,int>mp;
- mp['O']=1;
- mp['B']=2;
- mp['A']=3;
- mp['F']=4;
- mp['G']=5;
- mp['K']=6;
- mp['M']=7;
- string s1,s2;
- cin>>s1>>s2;
- if(mp[s1[0]]<mp[s2[0]])
- {
- cout<<"hotter"<<endl;
- return ;
- }
- else if(mp[s1[0]]>mp[s2[0]])
- {
- cout<<"cooler"<<endl;
- return ;
- }
- else
- {
- if(s1[1]<s2[1])
- {
- cout<<"hotter"<<endl;
- return ;
- }
- else if(s1[1]>s2[1])
- {
- cout<<"cooler"<<endl;
- return ;
- }
- else
- {
- cout<<"same"<<endl;
- return ;
- }
- }
- }
- signed main()
- {
- IOS;
- int _=1;
- cin>>_;
- while(_--)solve();
- return 0;
- }
复制代码 D - Distributed System
题目泉源:D - Distributed System
解题思路
这道题重要考察个差分的算法,如果不思量mod n的环境就把数组第i项和第i+n项末了加起来,题目意思是第0到ai-1项每次都会增长1,当然不能遍历着去加,以是就用一个前缀和数组记录改变的环境,末了利用前缀和公式求出即可。
代码实现
- #include<bits/stdc++.h>
- #define int long long
- #define endl '\n'
- #define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
- using namespace std;
- const int N=1e6+5;
- int n,q,ans[N],b[N],k,x,y;
- void solve()
- {
- cin>>n>>q;
- vector<int>a(2*n+10,0);
- int sum=0;
- while(q--)
- {
- cin>>x>>y;
- sum+=x/n;
- x%=n;
- a[y]++;
- a[y+x]--;
- }
- ans[0]=a[0];
- for(int i=1;i<n*2;i++)
- ans[i]=ans[i-1]+a[i];
- for(int i=0;i<n;i++)
- cout<<ans[i]+ans[i+n]+sum<<" ";
- cout<<endl;
- }
- signed main()
- {
- IOS;
- int _=1;
- cin>>_;
- while(_--)solve();
- return 0;
- }
复制代码 I - Square Puzzle
题目泉源:I - Square Puzzle
解题思路
这题没有什么规律,读完题后可以知道,一共就7种操纵:右移第一行,右移第二行,右移第三行,下移第一列,下移第二列,下移第三列,顺时针旋转90度。因为只是三乘三的九宫格,将全部方式遍历一遍也肯定不会超时,以是可以用广搜遍历每一种环境,然后将没种环境是否符合,如果符合看须要多少步,终极取最小,如果没有符合输出-1.
代码实现
- #include<bits/stdc++.h>
- #define int long long
- #define endl '\n'
- #define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
- using namespace std;
- const int N=1e6+5;
- map<string,int>ans;
- queue<string>q;
- string youyi(string a,int op)//右移函数
- {
- if(op==1)
- {
- char t=a[0];
- a[0]=a[2],a[2]=a[1],a[1]=t;
- return a;
- }
- if(op==2)
- {
- char t=a[3];
- a[3]=a[5],a[5]=a[4],a[4]=t;
- return a;
- }
- if(op==3)
- {
- char t=a[6];
- a[6]=a[8],a[8]=a[7],a[7]=t;
- return a;
- }
- }
- string xiayi(string a,int op)//下移函数
- {
- if(op==1)
- {
- char t=a[0];
- a[0]=a[6],a[6]=a[3],a[3]=t;
- return a;
- }
- if(op==2)
- {
- char t=a[1];
- a[1]=a[7],a[7]=a[4],a[4]=t;
- return a;
- }
- if(op==3)
- {
- char t=a[2];
- a[2]=a[8],a[8]=a[5],a[5]=t;
- return a;
- }
- }
- string xuanzhuan(string a)//顺时针旋转函数
- {
- char t=a[0];
- a[0]=a[6],a[6]=a[8],a[8]=a[2],a[2]=t;
- t=a[1];
- a[1]=a[3],a[3]=a[7],a[7]=a[5],a[5]=t;
- return a;
- }
- void bfs()
- {
- q.push("123456789");
- ans["123456789"]=0;
- while(q.size())
- {
- string g=q.front();
- q.pop();
- string t;
- t=youyi(g,1);
- if(ans[t]==0) q.push(t),ans[t]=ans[g]+1;
- t=youyi(g,2);
- if(ans[t]==0 )q.push(t),ans[t]=ans[g]+1;
- t=youyi(g,3);
- if(ans[t]==0) q.push(t),ans[t]=ans[g]+1;
- t=xiayi(g,1);
- if(ans[t]==0) q.push(t),ans[t]=ans[g]+1;
- t=xiayi(g,2);
- if(ans[t]==0) q.push(t),ans[t]=ans[g]+1;
- t=xiayi(g,3);
- if(ans[t]==0) q.push(t),ans[t]=ans[g]+1;
- t=xuanzhuan(g);
- if(ans[t]==0) q.push(t),ans[t]=ans[g]+1;
- }
- }
- void solve()
- {
- string s;
- map<char,char>mp;
- for(int i=1;i<=9;i++)
- {
- char ch;
- cin>>ch;
- mp[ch]='0'+i;
- }
- for(int i=1;i<=9;i++)
- {
- char ch;
- cin>>ch;
- s+=mp[ch];
- }
- if(s=="123456789")cout<<"0"<<endl;
- else if(ans[s]==0)cout<<-1<<endl;
- else cout<<ans[s]<<endl;
- }
- signed main()
- {
- IOS;
- bfs();
- int _=1;
- cin>>_;
- while(_--)solve();
- return 0;
- }
复制代码 E - Greatest Common Divisor
题目泉源:E - Greatest Common Divisor
解题思路
首先,答案肯定是s=
∑ai+k的因数。因此对s因数分解,然后在因数中罗列答案x。
为了让答案为x,须要把每个ai增长到最近的x的倍数,剩下的操纵次数还须要被x整除。如果x≤maxai,那么每x种数都要增长到同一个数,可以
一起盘算。这种环境的复杂度为调和级数O(maxai logmaxai)。
如果x>maxai,那么全部数都增长到同一个数,直接O(1)盘算。
整体复杂度O(n+√s+f(s)+maxai logmaxai),此中
f(s)≈6×103是因数个数。
代码实现
G - Assembly Line
题目泉源:G - Assembly Line
解题思路
题目意思是k名工人加工n个工件,第i个工件在第ti分钟加入工人wi的收件箱,每分钟工人在自己的收件箱拿出一个工件,完成加工后放入下
一个工人的收件箱(如果是末了一个工人则加工完成)。问
全部工件加工完成须要几分钟
工件i原本的竣事时间是(ti+k−wi),但每个时间点只能完成一个工件。
因此设ai表示从小到大排序后的工件完成时间,依次进行
更新ai←max(ai,ai−1+1)即可。复杂度O(nlogn)。
代码实现
- #include<bits/stdc++.h>
- #define int long long
- #define endl '\n'
- #define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
- using namespace std;
- const int N=1e6+5;
- int n,k,w,t,a[N];
- void solve()
- {
- cin>>n>>k;
- for(int i=1;i<=n;i++)
- {
- cin>>w>>t;
- a[i]=k-w+t;
- }
- sort(a+1,a+1+n);
- for(int i=1;i<=n;i++)
- a[i]=max(a[i],a[i-1]+1);
- cout<<a[n]<<endl;
-
- }
- signed main()
- {
- IOS;
- int _=1;
- cin>>_;
- while(_--)solve();
- return 0;
- }
复制代码 |