1. 程式人生 > >[多校補題]2017 Multi-University Training Contest 7 solutions BY 杭州二中

[多校補題]2017 Multi-University Training Contest 7 solutions BY 杭州二中

1005

Euler theorem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1322    Accepted Submission(s): 868


Problem Description HazelFan is given two positive integers a,b, and he wants to calculate amodb. But now he forgets the value of b and only remember the value of a
, please tell him the number of different possible results.
Input The first line contains a positive integer T(1T5), denoting the number of test cases.
For each test case:
A single line contains a positive integer a(1a109).
Output For each test case:
A single line contains a nonnegative integer, denoting the answer.

Sample Input 2 1 3
Sample Output 2 3

給定正整數a

,求對於所有正整數bbamodb有多少種可能的結果。1a109

顯然小於<a/2的每個非負整數c都是可能成為餘數的,取b=a-c即可,另外a本身也能成為餘數,而其他數顯然都不可能。

#include<bits/stdc++.h>
using namespace std;

int main(){
    int t;
    while(~scanf("%d",&t)){
        while(t--){
            int n;
            cin>>n;
            cout<<((n+1)/2)+1<<endl;
        }    
        
    }
    return 0;
}


1008(極角排序是什麼..待補)

平面直角座標系上有nn個整點,第ii個點有一個點權vali,座標為(xi,yi),其中不存在任意兩點連成的直線經過原點。這些整點兩兩之間連有一條線段,線段的權值為其兩端點的權值之積。你需要作一條過原點而不過任意一個給定整點的直線,使得和這條直線相交的線段的權值和最大。1n5×104,1vali104,xi,yi109

對於一條直線,線段權值和實際上就等於其兩邊點權和的乘積,所以把所有點按極角排個序,然後掃一圈就好了。


1010(待補..)

有一個長度為nn的整數序列{an},對其做mm次字首異或和,求最終的序列。1n2×105,1m109,0ai2301

可以發現做m次後,位置為x的初始值對位置為y的最終值的貢獻次數是一個只和m與y-x相關的組合式,而我們只關注這個次數的奇偶性。考慮Lucas定理,C(a,b)是奇數當且僅當把a,b二進位制表達後b中1的位置是a中1的位置的子集,於是這裡所有滿足條件的b有很好的性質,對每一個二進位制位獨立處理就能算出答案。


1011

Kolakoski

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1287    Accepted Submission(s): 884


Problem Description This is Kolakosiki sequence: 1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1. This sequence consists of 1 and 2, and its first term equals 1. Besides, if you see adjacent and equal terms as one group, you will get 1,22,11,2,1,22,1,22,11,2,11,22,1. Count number of terms in every group, you will get the sequence itself. Now, the sequence can be uniquely determined. Please tell HazelFan its nth element.
Input The first line contains a positive integer T(1T5), denoting the number of test cases.
For each test case:
A single line contains a positive integer n(1n107).
Output For each test case:
A single line contains a nonnegative integer, denoting the answer.
Sample Input 2 1 2
Sample Output 1 2

Kolakoski序列是一個僅由1和2組成的無限數列,是一種通過“自描述”來定義的數列。他的前幾項為
1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1,2,1,1,2,1,2,2,1,1,…
它的定義很簡單,若把數列中相同的數定為一組,令a(1)=1,a(2)=2,則a(n)等於第n組數的長度。
可以根據這個定義來推算第三項以後的數:例如由於a(2)=2,因此第2組數的長度是2,因此a(3)=2,;
由於a(3)=2,所以第三組數的長度是2,因此a(4)=a(5)=1;由於a(4)=1,a(5)=1,所以第四組數和第五組數的長度都為1,因此a(6)=2,a(7)=1,以此類推

直接打表找規律 兩個數列根據關係可以不斷互推增長 int打個1e7的表還是可以存下的

#include<iostream>
#include<cstdio>
using namespace std;

const int maxn = 1e7 +5;

int a[maxn] = {1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1};
int n;

int main()
{
    int indexa = 20;
    int indexb = 13;
    
    while(indexa < 1e7)
    {
        int temp = a[indexa - 1];
        if(temp == 1)
        {
            a[indexa] = 2;
        }
        else if(temp == 2)
        {
            a[indexa] = 1;
        }
        
        if(a[indexb] == 1)
        {
            indexa ++ ;
            indexb ++;
        }
        
        else if(a[indexb] == 2)
        {
            if(temp == 1)
            {
                a[indexa + 1] = 2;    
            }        
            
            else 
                a[indexa + 1] = 1;
                
            indexa +=2;
            indexb +=1;
        }
    }
    
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        cout<<a[n-1]<<endl;
    }
    
    return 0;
}