河南理工2019暑期选拔赛(ZZULIOJ)

A:

dp问题,往往想不出来思路的感觉都是dp问题。他的代码很简短,公式很简单,遗憾的那天天太黑我没看清楚。

#include 
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
const int MAXN = 1e5 + 7;

char s[1005];
int dp[1005];
int check(int i, int j)
{
    while(i < j)
    {
        if(s[i] != s[j])
            return 0;
        i++, j--;
    }
    return 1;
}

int main()
{
    ios::sync_with_stdio(0);
    int t;
    cin>>t;
    while(t--)
    {
        cin>>s+1;
        int len = strlen(s+1);
        fill(dp, dp+1005, 1005);
        dp[0] = 0;
        for(int i = 1; i <= len; i++)
        {
            //cout<#include 
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
const int MAXN = 1e5 + 7;

ll arr[MAXN];
ll n, k, l, mid, r;

int check(ll mid)
{
    ll cnt = 0, sum = 0;
    for(int i = 1; i <= n; i++)
    {
        if(arr[i] > mid)
        {
            cnt = k;
            break;
        }
        sum += arr[i];
        if(sum > mid)
        {
            cnt++;
            sum = arr[i];
        }
    }
    return cnt;
}

int main()
{
    ios::sync_with_stdio(0);
    cin>>n>>k;
    l = r = 0;
    for(int i = 1; i <= n; i++)
    {
        cin>>arr[i];
        r += arr[i];
    }
    while(l <= r)
    {
        mid = (l + r)/2;
        if(check(mid) < k) r = mid - 1;
        else l = mid + 1;
    }
    cout<

C:

签到题。

#include 
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
const int MAXN = 1e5 + 7;
 
int main()
{
    ios::sync_with_stdio(0);
    string s;
    while(getline(cin,s))
    {
        string ss;
        if(s[0] >= 'a')
        s[0] -= 32;
        ss += s[0];
        for(int i = 1; i < s.size(); i++)
        {
            if(s[i-1] == ' ')
            {
                if(s[i] >= 'a')
                    s[i] -= 32;
                ss += s[i];
            }
        }
        cout<

D:

这道题有点坑啊,基本上没有1A的,因为cin过不了,关不关同步流都过不了,而且还爆long long。

为什么答案是a+b?因为二项式打开后除了开头结尾都会乘p,所以都为0了。开头结尾用费马小定理就变成a和b了。

#include 
using namespace std;
#define ll long long
#define ull unsigned long long
const int MAXN = 1e5 + 7;

int main()
{
    //ios::sync_with_stdio(0);
    int t;
    scanf("%d", &t);
    ull a, b, p;
    while(t--)
    {
        scanf("%llu%llu%llu", &a, &b, &p);
        printf("%llu\n", (a+b)%p);
    }

    return 0;
}

E:

比赛的时候没写出来,虽然想到了反着推,但没有深入,原理也是很简单,从后往前,如果速度之差乘时间小于距离之差,球就少一,否则把最后一个球更新为它就行。

#include 
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
const int MAXN = 1e5 + 7;

struct node
{
    ll x;
    ll v;
}stu[MAXN], stt;

int main()
{
    ios::sync_with_stdio(0);
    ll n, t;
    cin>>n>>t;
    for(int i = 0; i < n; i++)
    {
        cin>>stu[i].x>>stu[i].v;
    }
    stt.x = stu[n-1].x;
    stt.v = stu[n-1].v;
    int ans = n;
    for(int i = n-2; i >= 0; i--)
    {
        if(stt.v < stu[i].v && (stu[i].v-stt.v)*t>=stt.x-stu[i].x)
            ans--;
        else
        {
            stt.x = stu[i].x;
            stt.v = stu[i].v;
        }
    }
    cout<

F:

虽然代码很简短,但是开始感觉还是不好想到的。求前缀和并取余,用一个map存取sum,不存在时等于i,存在时就是i到第一次存的mp[sum]这,然后跑到n就可以了。

#include 
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
const int MAXN = 1e5 + 7;

int arr[MAXN];
map  mp;

int main()
{
    ios::sync_with_stdio(0);
    int n, k;
    cin>>n>>k;
    int ans = 0, sum = 0;
    mp[0] = 0;//sum = 0时代表前缀和能整除k
    for(int i = 1; i <= n; i++)
    {
        cin>>arr[i];
        sum = (sum + arr[i]) % k;
        if(!mp.count(sum)) mp[sum] = i;//sum没不存在时
        else ans = max(ans, i-mp[sum]);
    }
    cout<

G:

用快乘防止爆long long。

#include 
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
const int MAXN = 1e6 + 7;
const int MOD = 1e9 + 7;
 
ll m, a, c, x0, n, g;
ll arr[MAXN];
 
ll qmul(ll x, ll y, ll mod)
{
    return (x * y - (ll)(x / (ll)mod * y + 1e-3) *mod + mod) % mod;
}
 
void inv()
{
    for(int i = 1; i <= n; i++)
    {
        arr[i] = (qmul(a, arr[i-1], m) + c) % m;
    }
}
 
int main()
{
    ios::sync_with_stdio(0);
    cin>>m>>a>>c>>x0>>n>>g;
    c %= m;
    arr[0] = x0;
    inv();
    cout<

H:

先把所有可能性都记录一下,然后按次序找平行的,然后ans--。

#include 
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
const int MAXN = 1e5 + 7;
 
int vis[MAXN];
int arr[205][2];
int brr[MAXN][2];
int main()
{
    ios::sync_with_stdio(0);
    int n, ans = 0;
    cin>>n;
    for(int i = 0; i < n; i++)
    {
        cin>>arr[i][0]>>arr[i][1];
    }
    int pos = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = i+1; j < n; j++)
        {
            brr[pos][0] = arr[j][0]-arr[i][0];
            brr[pos++][1] = arr[j][1]-arr[i][1];
        }
    }
    ans = pos;
    for(int i = 0; i < pos; i++)
        vis[i] = 1;
    for(int i = 0; i < pos; i++)
    {
        if(vis[i] == 1)
        {
            for(int j = i+1; j < pos; j++)
            {
                if(brr[j][0]*brr[i][1] == brr[j][1]*brr[i][0])
                {
                    ans--;
                    vis[j] = 0;
                }
            }
        }
 
    }
    cout<

I:

简单题我wa了四发,感觉这题在搞我,最后发现竟然是长宽输出反了。。。

不过遇到了一个玄学问题,在cb上输出时.3lf输出为0.000,换成.3f就可以正常输出了。

#include 
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
const int MAXN = 1e5 + 7;

int main()
{
    //ios::sync_with_stdio(0);
    ll a;
    double b, c, d;
    scanf("%lld", &a);
    if(a%8 == 0)
    {
        ll q = a/8;
        ll w = a/2-q;
        printf("%lld %lld %lld\n", w, q, q*w);
    }
    else
    {
        b = a/8.0;
        c = a/2.0 - b;
        d = b*c;
        printf("%.3f %.3f %.3f\n", c, b, d);
    }

    return 0;
}

 

你可能感兴趣的:(郑州轻工业OJ)