链接:Dashboard - Codeforces Round 867 (Div. 3) - Codeforces
头一次div3做出来四题,第五题也差临门一脚,赛后看到别人e题跟自己几乎一样的思路肠悔青了,还得练才行
A. TubeTube Feed
签到题,找时间+当前页面耗时最大暴力水过~
//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<math.h>
#include<string.h>
#include<set>
using namespace std;
#define int long long
#define endl "\n"
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int mod=1000000007;
typedef pair<int,int>PII;
int a[105],b[105];
signed main(void){
ios;
int q;
cin>>q;
while(q--){
int n,t,cnt=-1,mi=0,xb=-1;
cin>>n>>t;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++){
cnt++;
cin>>b[i];
if(cnt+a[i]<=t){
if(max(b[i],mi)==b[i]){
mi=b[i];
xb=i;
}
}
}
if(xb==-1)cout<<-1<<endl;
else cout<<xb<<endl;
}
return 0;
}
B. Karina and Array
简单思维题,只需先排序然后比较前俩个元素之和与后俩个元素之和就可以得出答案
//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<math.h>
#include<string.h>
using namespace std;
#define int long long
#define endl "\n"
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int a[2000005];
signed main(void){
ios;
int t;
cin>>t;
while(t--){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+1+n);
int ans1=a[n]*a[n-1];
int ans2=a[1]*a[2];
cout<<max(ans1,ans2)<<endl;
}
return 0;
}
C. Bun Lover
找规律的题,巧克力黄条从中间垂直竖条开始对称长度和是1 2 4 6以此类推,但时间设了个坑,要用高中学的Sn公式而不是循环+2,循环+2亲试tle3
// Problem: C. Bun Lover
// Contest: Codeforces - Codeforces Round 867 (Div. 3)
// URL: https://codeforces.com/contest/1822/problem/C
// Memory Limit: 256 MB
// Time Limit: 3000 ms
//
// Powered by CP Editor (https://cpeditor.org)
//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<math.h>
#include<string.h>
using namespace std;
#define int long long
#define endl "\n"
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
signed main(void){
ios;
int tt;
cin>>tt;
while(tt--){
int n;
cin>>n;
int ans=4*4+10,t=n-3;
int temp1=(t-1)*3;
int temp2=(t-1)*(t+2)/2;
ans+=2*temp1+2*temp2;
//cout<<ans<<endl<<4*n<<endl;
cout<<ans+n-4<<endl;
}
return 0;
}
D. Super-Permutation
听群友说这个好像是oiwiki上的原题,没写过。打表找的规律,附上打表代码
打表代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int N=3e5+5;
int n;
int h[10],st[10];
int flat=0;
void dfs(int x)
{
if(x==n+1){
vector<int> s(n+1);
set<int> z;
for(int i=1;i<=n;i++){
s[i]=s[i-1]+h[i];
z.insert(s[i]%n+1);
}
int cnt=1;
if(z.size()==n){
for(auto x: z){
if(x==cnt){
cnt++;
continue;
}
}
if(cnt==n+1){
flat=1;
for(int i=1;i<=n;i++){
cout<<h[i]<<" ";
}
cout<<endl;
}
}
}
for(int i=1;i<=n;i++){
if(!st[i]){
st[i]=1;
h[x]=i;
dfs(x+1);
st[i]=0;
}
}
}
void solve()
{
cin>>n;
dfs(1);
if(!flat){
cout<<-1<<endl;
}
}
int main()
{
int t=1;
//cin>>t;
while(t--){
solve();
}
system("pause");
return 0;
}
ac代码:
// Problem: D. Super-Permutation
// Contest: Codeforces - Codeforces Round 867 (Div. 3)
// URL: https://codeforces.com/contest/1822/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<math.h>
#include<string.h>
#include<set>
#include<unordered_map>
#include<numeric>//partial_sum
using namespace std;
#define int long long
#define endl "\n"
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
signed main(void){
ios;
int t;
cin>>t;
while(t--){
int n;
cin>>n;
if(n%2==1){
if(n==1)cout<<1<<endl;
else cout<<-1<<endl;
}
else{
//cout<<n<<" ";
int x=n;
for(int i=1;i<=n/2;i++){
cout<<x<<" "<<i*2-1<<" ";
x-=2;
}
cout<<endl;
}
}
return 0;
}
E. Making Anti-Palindromes
本场最遗憾的题,这题出了估计rating得加接近100,先贴出赛时没过的代码
// Problem: E. 制作反回文
// Contest: Codeforces - Codeforces Round 867 (Div. 3)
// URL: https://codeforces.com/contest/1822/problem/E
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<math.h>
#include<string.h>
#include<set>
#include<unordered_map>
#include<numeric>//partial_sum
using namespace std;
#define int long long
#define endl "\n"
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
char a[200005];
signed main(void){
ios;
int t;
cin>>t;
while(t--){
int n;
map<char,int>b;
map<char,int>c;
cin>>n;
int f=1;
int m=0;
for(int i=1;i<=n;i++){
cin>>a[i];
c[a[i]]++;
m=max(m,c[a[i]]);
if(i!=1&&a[i]!=a[i-1])f=0;
}
if(n%2==1||f||m>n/2){
cout<<-1<<endl;
continue;
}
int ma=0;
for(int i=1;i<=n/2;i++){
if(a[i]==a[n-i+1])b[a[i]]++;
if(b[a[i]]==max(b[a[i]],ma)){
ma=max(b[a[i]],ma);
//temp=b[a[i]]
}
}
int sum=0;
for(auto i:b){
sum+=i.second;
}
//cout<<sum<<" "<<ma<<" ";
if(ma*2>sum)cout<<ma<<endl;
else{
cout<<sum-ma<<endl;
}
/*if(ma>=n/2-ma)cout<<ma<<endl;
else*/
}
return 0;
}
这题思路是:首先长度如果为奇数或者单个字母数量出现次数超过总长度的一半就肯定不成立,
然后形成回文的字符其实只要一边互相交换就可以不形成回文了,具体操作如下
统计每个形成回文字符的各个字符类型的数量sum和最多出现的那个形成回文的字符的数量max,我的代码里的sum和ma是只统计了一边的数量所以后面比较*了2,然后比较是max与sum的二分之一比较,如果大于就直接输出ma,否则输出(sum+1)/2,+1是因为如果sum是奇数的话,/2会漏掉中间那个字符。
比赛时就是那个输出的else想歪了,以为只用换sum-ma次就能完成所有调换,赛后画图+结合别人思路发现并不是这么回事
ac代码:
// Problem: E. 制作反回文
// Contest: Codeforces - Codeforces Round 867 (Div. 3)
// URL: https://codeforces.com/contest/1822/problem/E
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<math.h>
#include<string.h>
#include<set>
#include<unordered_map>
#include<numeric>//partial_sum
using namespace std;
#define int long long
#define endl "\n"
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
char a[200005];
signed main(void){
ios;
int t;
cin>>t;
while(t--){
int n;
map<char,int>b;
map<char,int>c;
cin>>n;
int f=1;
int m=0;
for(int i=1;i<=n;i++){
cin>>a[i];
c[a[i]]++;
m=max(m,c[a[i]]);
if(i!=1&&a[i]!=a[i-1])f=0;
}
if(n%2==1||f||m>n/2){
cout<<-1<<endl;
continue;
}
int ma=0;
for(int i=1;i<=n/2;i++){
if(a[i]==a[n-i+1])b[a[i]]++;
if(b[a[i]]==max(b[a[i]],ma)){
ma=max(b[a[i]],ma);
//temp=b[a[i]]
}
}
int sum=0;
for(auto i:b){
sum+=i.second;
}
//cout<<sum<<" "<<ma<<" ";
if(ma*2>sum)cout<<ma<<endl;
else{
cout<<(sum+1)/2<<endl;
}
/*if(ma>=n/2-ma)cout<<ma<<endl;
else*/
}
return 0;
}