这场A一发7mins,Bwa2发20mins,C卡题了一会换题,D题5-7mins,E题40mins,F题假算法。
一开始A题5mins写完交的时候输出格式错了再读题耽误了2mins,B题写完13mins之后少考虑了两种情况,各RE了两发,20minsac,送了20+7分钟的罚时,C题没有细想跳开了,D题秒了,E2用的线段树T了,没有优化,F题没有耐心读。
总结:
- 读题需要读输出格式
- B题遇到有的出题人会在那种情况出fst点,总结下来就是枚举因子需要考虑因子相同的情况。
- C题可以用next_permutation写就不麻烦了。
- 开E2这种蹭时间线边缘的题时,要先开其他题。
- F题证明了自己对最小生成树俩个算法理解不够深。
题解:
A.
题意:给你两个区间让你O1输出两个数,使得这两个数都在任意个区间里,且第一个数在第一个区间里,第二个数在第二个区间里。
思路:取左端点最小的点,和未被取的最右边的点。
代码:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int main(){
//IO;
int q;cin>>q;
while(q--){
int l,r,l2,r2;cin>>l>>r>>l2>>r2;
bool ok = 0;
if(l<l2)swap(l,l2),swap(r,r2),ok=1;
if(ok)cout<<l2<<' '<<r<<'\n';
else cout << r<<' '<<l2<<'\n';
}
return 0;
}
B.
题意:给出两个数的所有因子,输出这两个数。
思路:取最大的因子为数1,用multiset删除掉所有数1的因子,输出剩下最大的因子。
代码:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int main(){
//IO;
int n;cin>>n;
multiset<int>s;
forn(i,n){
int x;cin>>x;
s.insert(x);
}
//cerr<<"!@"<<'\n';
int b = *s.rbegin();
int m = sqrt(b);
for(int i = 1;i<=m;i++)if(b%i==0){
s.erase(s.find(i));
if(i*i!=b)s.erase(s.find(b/i));
}
cout << *s.rbegin() <<' '<<b<<'\n';
return 0;
}
C.
题意:长1e5的字符串每个字符只会是RBG,求最少修改字符使得相同字符的位之差都为3。
思路:6个排列枚举出最小的,然后循环输出。
代码:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
string a[6]={
"RGB"