普及组—2023年2.12日打卡

_谦言万语 2023-02-12 23:26:31

T1

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e4+10;
typedef long long LL;
LL ans=0x3f3f3f3f;
int n;
int a[N], s[N*2];

int main()
{
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>a[i]; 
    for(int i=0; i<n; i++)
    {
        LL sum=0;
        for(int j=1; j<n; j++)
            sum+=j*a[(i+j)%n];
        /*
        for(int j=i+1; i!=j; j=(j+1)%n)
            sum+=((j+n-i)%n)*a[j%n];  
        */
        ans=min(ans,sum);
    }
    cout<<ans;
    return 0;
}

 

 

T2

class Solution {
public:
    void reOrderArray(vector<int> &array) {
         int l=0, r=array.size()-1;
         while(l<r)
         {
             while(l<r && array[l]%2!=0) l++;
             while(l<r && array[r]%2==0) r--;
             if(l<r) swap(array[l],array[r]);
         }
    }
};

 

T3

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int n,s;

bool huiwen(int x,int h)
{
    string s;
    while(x)
    {
        s+=((x%h)+'0');
        x/=h;
    }
    string ss=s;
    reverse(ss.begin(), ss.end());
    if(ss==s) return true;
    else return false;
}

bool check(int x)
{
    int res=0;
    for(int i=2; i<=10; i++) 
        if(huiwen(x,i)) res++;
    return res>=2;
}

int main()
{
    cin>>n>>s;
    for(int i=s+1; n; i++)
    {
        if(check(i))
        {
            cout<<i<<endl;
            n--;
        }
    }
    return 0;
}

 

T4

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1005;
int x[N];
int n,res;

int main()
{
    cin>>n;
    for(int i=1; i<=n; i++) cin>>x[i];
    sort(x+1,x+1+n);
    for(int i=1; i<=n; i++)
        for(int j=i+1; j<=n; j++)
        {
            int l=lower_bound(x+1,x+n+1,2*x[j]-x[i])-(x+1);
            int r=upper_bound(x+1,x+n+1,3*x[j]-2*x[i])-(x+1);
            res+=r-l;
        }
    cout<<res;
    return 0;
}

 

...全文
7 回复 打赏 收藏 举报
写回复
回复
切换为时间正序
请发表友善的回复…
发表回复
发帖
高校算法学习社区

4.3w+

社区成员

和众多高校算法内卷分子,一起学习和交流算法那。浓郁的算法交流氛围,拒绝躺平,有效内卷。加入我们,私信我拉你入核心内卷群。
算法数据结构leetcode 个人社区
社区管理员
  • 执 梗
  • Dream-Y.ocean
  • ღCauchyོꦿ࿐
加入社区
帖子事件
创建了帖子
2023-02-12 23:26
社区公告

 刷题!