cf 1450 F The Struggling Contestant

link
题意:给一长度为n的数组A,求以排列p满足A[pi],A[pi-1]不同,定义每一个排列的权值为abs(pi-pi-1) >1 的i的个数。输出满足条件排列的最小权值。无解输出-1
思路:如果不考虑权值的话就是一个插数的过程,那么有解的情况就是出现次数最多的数要小于(n+1)/2。
考虑怎么构造权值最小的排列。首先对于ai==ai-1的这些位置是一定要分开的。记为k,那么此时最小可能的答案就为k(翻转,重拍每个排列后每个端点的代价都为1),考虑什么情况下这个k会变大,无非就是某个数作为端点的次数超过k+2,那么此时就需要一些额外的段,将k变大即可

#include<bits/stdc++.h>
#define pb push_back
#define SZ(x) (int)(x.size())
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 6;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int _,n,k;
int a[maxn],f[maxn],cnt[maxn];
int main() {
    for(scanf("%d",&_);_;_--) {
        scanf("%d",&n);k=0;
        for(int i=1;i<=n;i++) {
            scanf("%d",&a[i]);
            if(a[i]==a[i-1]) {
                k++;
                f[a[i]]+=2;
            }
            cnt[a[i]]++;
        }
        f[a[1]]++;f[a[n]]++;
        int mx=0,m=0;
        for(int i=1;i<=n;i++) mx=max(mx,cnt[i]),m=max(m,f[i]);

        if((n+1)/2<mx) printf("-1\n");
        else printf("%d\n",k+max(0,m-k-2));
        for(int i=1;i<=n;i++) f[i]=cnt[i]=0;
    }
}
Good day! The cost of university tuition fees has been a topic of concern among students and parents alike. Some argue that the fees are too high, limiting access to higher education, while others believe that the cost is justified by the quality of education and facilities provided. In this article, we will examine the different perspectives surrounding university tuition fees and explore the impact they have on students. Firstly, it is important to acknowledge that higher education is a valuable investment. Research has shown that individuals with a university degree earn significantly more over their lifetime compared to those without. This is because university education equips students with new skills, knowledge and networks, enhancing their employability and career prospects. However, the rising cost of tuition fees is making it increasingly difficult for students from lower-income families to pursue a degree. This is because tuition fees may not only be a financial burden but can also discourage students psychologically and create extra stress. Furthermore, many students are forced to accumulate significant debt in order to pay for their education. This debt can leave them struggling financially for years after graduation, burdening them with the responsibility to pay back the borrowed amount. In some cases, students are forced to delay important milestones, such as buying a house or starting a family, due to this financial burden. In addition to the financial impact, the high cost of tuition fees can also have a psychological impact on students. It can create a sense of pressure to succeed academically in order to justify the cost of their education, potentially leading to burnout, stress and anxiety. It can also lead to a sense of resentment towards the university and the feeling that students are being taken advantage of. In conclusion, university tuition fees are a complicated issue with both positive and negative effects. While it is important to acknowledge the value of higher education, we must also address the rising cost of tuition fees and the impact it has on students. Whether it is by increasing government funding for education, providing more scholarships, or reducing operational costs, solutions must be found to ensure that access to higher education is available to all, regardless of their financial background. I hope this article was informative and useful to you. Good luck with your studies!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值