2018浙江省赛(ACM) The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple

比赛链接

F. Now Loading!!!

Time Limit: 1 Second Memory Limit: 131072 KB
DreamGrid has integers . DreamGrid also has queries, and each time he would like to know the value of
for a given number , where , .

Input
There are multiple test cases. The first line of input is an integer indicating the number of test cases. For each test case:

The first line contains two integers and () – the number of integers and the number of queries.

The second line contains integers ().

The third line contains integers ().

It is guaranteed that neither the sum of all nor the sum of all exceeds .

Output
For each test case, output an integer , where is the answer for the -th query.

Sample Input
2
3 2
100 1000 10000
100 10
4 5
2323 223 12312 3
1232 324 2 3 5
Sample Output
11366
45619

题目描述:

给出n个数,m次询问,每次询问给出一个p,对于每次询问按照公式求值,最后按照要求输出

代码:

#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <stack>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int MaxN = 5e5 + 5;
const int pt = 1e9;

int n;
LL a[MaxN], sum[MaxN][32]; //注意爆内存

int get_R(LL x) {
    int l = 1, r = n, ans = 0;
    while(l <= r) {
        int mid = (l + r) >> 1;
        if(a[mid] <= x) ans = mid, l = mid + 1;
        else r = mid - 1;
    }
    return ans;
}
int main() {
    int t, m;
    scanf("%d", &t);
    while(t--) {
        scanf("%d %d", &n, &m);
        for(int i = 1; i <= n; i++) scanf("%lld", &a[i]);
        sort(a + 1, a + 1 + n);
        for(int j = 1; j <= 31; j++) //前缀和
            for(int i = 1; i <= n; i++) 
                sum[i][j] = sum[i - 1][j] + (a[i] - (a[i] % j)); //注意向下取整
        LL ans = 0LL;
        for(int i = 1; i <= m; i++) {
            LL p; scanf("%lld", &p);
            LL s = 1LL, res = 0LL;
            int L = 0, tot = 0;
            while(s <= a[n]) {
                s *= p; tot++;
                int R = get_R(s); //二分找答案
                res = (res + ((sum[R][tot] - sum[L][tot]) / tot) % pt) % pt;
                L = R;
            }
            ans = (ans + (res * i) % pt) % pt;
        }
        printf("%lld\n", ans);
    }
    return 0;
}

I. Magic Points

ZOJ Problem Set - 4032
Magic Points
Time Limit: 1 Second Memory Limit: 65536 KB Special Judge
Given an integer , we say a point on a 2D plane is a magic point, if and only if both and are integers, and exactly one of the following conditions is satisfied:

and ;

and ;

and ;

and .

It’s easy to discover that there are magic points in total. These magic points are numbered from to in counter-clockwise order starting from .

DreamGrid can create magic lines from these magic points. Each magic line passes through exactly two magic points but cannot be parallel to the line or (that is to say, the coordinate axes).

The intersections of the magic lines are called dream points, and for some reason, DreamGrid would like to make as many dream points as possible. Can you tell him how to create these magic lines?

Input
There are multiple test cases. The first line of input contains an integer (about 100), indicating the number of test cases. For each test case, there is only one integer ().

Output
For each case output integers in one line separated by one space, indicating that in your answer, point and point is connected by a line for all .

If there are multiple answers, you can print any of them.

Sample Input
3
2
3
4
Sample Output
0 2 1 3
1 4 2 5 3 6
0 6 1 9 3 8 4 10

题目描述:

给出一个n,在符合条件的点中构造直线且交点最多

代码:

#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <stack>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int MaxN = 5e5 + 5;
const int pt = 1e9;


int main() {
    int t, n;
    scanf("%d", &t);
    while(t--) {
        scanf("%d", &n);
        if(n == 2) printf("0 2 1 3\n");
        else if(n == 3) printf("1 4 2 5 3 6\n");
        else if(n == 4) printf("0 6 1 9 3 8 4 10\n");
        else if(n == 5) printf("0 5 1 6 2 7 3 8 11 13\n");
        else {
            for(int i = 0; i < n - 1; i++) printf("%d %d ", i, i + n);
            printf("%d %d\n", n * 4 - 5, n * 2);
        }
    }
    return 0;
}

J. CONTINUE…?

DreamGrid has classmates numbered from to . Some of them are boys and the others are girls. Each classmate has some gems, and more specifically, the -th classmate has gems.

DreamGrid would like to divide the classmates into four groups , , and such that:

Each classmate belongs to exactly one group.

Both and consist only of girls. Both and consist only of boys.

The total number of gems in and is equal to the total number of gems in and .

Your task is to help DreamGrid group his classmates so that the above conditions are satisfied. Note that you are allowed to leave some groups empty.

Input
There are multiple test cases. The first line of input is an integer indicating the number of test cases. For each test case:

The first line contains an integer () – the number of classmates.

The second line contains a string () consisting of 0 and 1. Let be the -th character in the string . If , the -th classmate is a boy; If , the -th classmate is a girl.

It is guaranteed that the sum of all does not exceed .

Output
For each test case, output a string consists only of {1, 2, 3, 4}. The -th character in the string denotes the group which the -th classmate belongs to. If there are multiple valid answers, you can print any of them; If there is no valid answer, output “-1” (without quotes) instead.

Sample Input
5
1
1
2
10
3
101
4
0000
7
1101001
Sample Output
-1
-1
314
1221
3413214

题目描述:

给出n个为0或1数字,每个数字的价值为i,0只能在1、2集合中,1只能在3、4集合中,要求集合1、3的价值和等于2、4的价值和

solution:

暴力枚举

代码:

#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <stack>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int MaxN = 1e5 + 5;

int a[MaxN], ans[MaxN];

int main() {
    int t, n;
    scanf("%d", &t);
    while(t--) {
        scanf("%d", &n);
        for(int i = 1; i <= n; i++) scanf("%1d", &a[i]);
        LL sum = n * 1LL * (n + 1) / 2;
        if(sum % 2) printf("-1\n");
        else {
            sum /= 2;
            for(int i = n; i >= 1; i--) {
                if(sum >= i) {
                    sum -= i;
                    ans[i] = (a[i] == 0) ? 1 : 3;
                }
                else ans[i] = (a[i] == 0) ? 2 : 4;
            }
            for(int i = 1; i <= n; i++) printf("%d", ans[i]);
            printf("\n");
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/jasmineaha/article/details/80187504