1. 程式人生 > 其它 >【十月】第一次提高題單

【十月】第一次提高題單

以下是提高題單的內容iヾ(≧▽≦*)o請在有一定基礎的前提下食用

p1007

#include<cstdio>
#include<algorithm>
using namespace std;
int l,n;
int a;
int ansn,ansx;
int main()
{
    scanf("%d%d",&l,&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a);
        ansn=max(ansn,min(a,l-a+1));
        ansx=max(ansx,max(a,l-a+1
)); } printf("%d %d",ansn,ansx); }
View Code

p1843

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,a,b;
int wet[500005];
int l,r,mid;
int maxn,ans;
bool check(int x)
{
    int c=x;
    for(int i=1;i<=n;i++)
    {
        
        if(wet[i]<=a*x) continue
; else { int t=0; if((wet[i]-a*x)%b!=0) t=1; c=c-(wet[i]-a*x)/b-t; } if(c<0) return 0; } return 1; } int main() { scanf("%d%d%d",&n,&a,&b); for(int i=1;i<=n;i++) { scanf("%d",&wet[i]); maxn
=max(wet[i],maxn); } l=0;r=ans=maxn; while(l<=r) { mid=(l+r)/2; if(check(mid)) { ans=min(ans,mid); r=mid-1; } else l=mid+1; } printf("%d",ans); }
View Code

p1020

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int h[21];
int fugai=0;
int sum=0;
int res=0,res1=0;
int f[21];
int dp[21];
void change(int x)
{
    if(fugai==sum) return;
    if(h[f[x]]==0) return;
    h[f[x]]=0;
    fugai++;
    change(f[x]);
}
void work()
{
    while(fugai<sum)
    {    
    res1++;
    memset(f,0,sizeof(f));
    for(int i=1;i<=sum;i++) dp[i]=0;
    dp[1]=1;
    int ans;
    for(int i=2;i<=sum;i++)
    {
        if(h[i]==0) continue;
        ans=dp[i];
        for(int j=1;j<i;j++)
        {
            if(h[j]==0) continue;
            if(h[i]<=h[j]&&dp[j]>ans) 
            {
                f[i]=j;
                ans=dp[j];
            }
        }
        if(f[i]==0) f[i]=i;
        dp[i]=ans+1;
    }
    ans=0;
    for(int i=1;i<=sum;i++) if(dp[ans]<dp[i]) ans=i;
    res=max(res,dp[ans]);
    fugai++;
    h[ans]=0;
    change(ans);    
    }
    return;
}
int main()
{
    int num[85];
    char a=1; 
    int t=0;
    while(a!='\n')
    {
        scanf("%c",&a);
        if(a=='\n') 
        {
            sum++;    
            for(int i=1;i<=t;i++)
            {
                if(num[i]<=9&&num[i]>=0) h[sum]=h[sum]*10+num[i];
            }
            break;
        }
        if(a!=' ') num[++t]=a-'0';
        else {
            sum++;
            for(int i=1;i<=t;i++)
            {
                if(num[i]<=9&&num[i]>=0) h[sum]=h[sum]*10+num[i];
            }
            memset(num,0,sizeof(num));
        }
    }
    work();
    printf("%d\n%d",res,res1);

}
View Code

p1090

#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
int n;
int a[10005];
struct node{
    int m;
    bool operator < (const node &a) const
    {
        return a.m<m;
    }
};
int ans;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    priority_queue<node>Q;
    for(int i=1;i<=n;i++)
    {
        node p;
        p.m=a[i];
        Q.push(p);
     } 
    for(int i=1;i<n;i++)
    {
        node q=Q.top();
        Q.pop();
        int sum=q.m;
        q=Q.top();
        Q.pop();
        sum+=q.m;
        q.m=sum;
        Q.push(q);
        ans+=sum;
    }
    printf("%d",ans);
    return 0;
}
View Code

p1080

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define N 1010

using namespace std;


inline int read(){
    int x = 0;
    char ch = getchar();
    while (ch < '0' && ch > '9') ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
    return x;
}

struct node{
    int num[100000];
    node(){
        memset(num, 0, sizeof(num));
    }
    bool operator > (const node &b) const{
        if(num[0] > b.num[0]) return 1;
        if(num[0] < b.num[0]) return 0;
        for(int i = num[0]; i >= 1; i--){
            if(num[i] > b.num[i]) return 1;
            if(num[i] < b.num[i]) return 0;
        }
        return 0;
    }
    node operator + (const node &b) const{
        node c;
        c.num[0] = min(100, max(num[0], b.num[0]));
        for(int i = 1; i <= c.num[0]; i++)
            c.num[i] = num[i] + b.num[i];
        for(int i = 1; i <= c.num[0]; i++){
            c.num[i + 1] += c.num[i] / 10;
            c.num[i] %= 10;
        }
        if(c.num[c.num[0] + 1]) c.num[0]++;
        return c;
    }
    node operator * (int b) const{
        node c;
        int w = 0;
        c.num[0] = num[0];
        for(int i = 1; i <= c.num[0]; i++){
            c.num[i] = num[i] * b + w;
            w = c.num[i] / 10;
            c.num[i] %= 10;
        }
        if(w) c.num[++c.num[0]] = w;
        while(c.num[c.num[0]] >= 10){
            c.num[c.num[0] + 1] = c.num[c.num[0]] / 10;
            c.num[c.num[0]++] %= 10;
        }
        return c;
    }
    node operator / (const int b) const{
        node c;
        int w = 0;
        for(int i = num[0]; i >= 1; i--){
            w = w * 10 + num[i];
            c.num[i] = w / b;
            w %= b;
        }
        c.num[0] = num[0];
        while(!c.num[c.num[0]] && c.num[0] > 1) c.num[0]--;
        return c;
    }
}ans, tmp, maxs, A;
int B;
struct people{
    int a,b,val;
    bool operator < (const people &b){
        return val < b.val;
    }
}p[N];
int n;

int main(){
    ios :: sync_with_stdio(false);
    cin >> n >> p[1].a >> p[1].b;
    p[1].val = p[1].a * p[1].b;
    for(int i = 2; i <= n + 1; i++){
        cin >> p[i].a >> p[i].b;
        p[i].val = p[i].a * p[i].b;
    }
    sort(p + 2, p + 2 + n);
    ans.num[0] = ans.num[1] = 1;
    for(int i = 2; i <= n + 1; i++){
        ans = ans * p[i - 1].a;
        tmp = ans / p[i].b;
        if(tmp > maxs)
            memcpy(maxs.num, tmp.num, sizeof(tmp.num));
    }
    for(int i = maxs.num[0]; i >= 1; i--)
        cout << maxs.num[i];
    cout << endl;
    return 0;
}
View Code