1. 程式人生 > >Codeforces Round #319 (Div. 2)(A,B,C,E)

Codeforces Round #319 (Div. 2)(A,B,C,E)

Codeforces Round #319 (Div. 2)

A.Multiplication Table

題意:

求m在n*n的加法表中出現了幾次

思路:

列舉1到n,累計能整除m的情況。

程式碼:

/*
* @author FreeWifi_novicer
* language : C++/C
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string> #include<map> #include<set> #include<vector> #include<queue> using namespace std; #define clr( x , y ) memset(x,y,sizeof(x)) #define cls( x ) memset(x,0,sizeof(x)) #define mp make_pair #define pb push_back typedef long long lint; typedef long long ll; typedef
long long LL; int main(){ // freopen("input.txt","r",stdin); lint n , x; while( cin >> n >> x ){ lint cnt = 0 ; for( lint i = 1 ; i <= n ; i++ ){ if( x >= i && x % i == 0 && x / i <= n ) cnt++ ; } cout << cnt << endl ; } return
0; }

B. Modulo Sum

題意:

輸入n個數以及m,問能否從n中選一些數,這些數的和能被m整除。

思路:

分兩種情況:

n >= m

n >= m 時,必定YES,證明如下:
考慮n個數的前i項和,每一個前i項和 sumi%m=qi,顯然 0qim1
其中若有 qi=0,則YES;若所有 qi 均不為 0,則必存在兩個或以上的 qi 相等 (因為共有n個前i項和), 即存在兩個不相等的 sumi 模除 m 的值相等,絕對差值即為 m 的倍數,故也是YES。

n < m

n < m 時 , 我們用 dp[i][j] 表示前i項是否存在組合除以m得到餘數j,那麼答案就是dp[n][0]
顯然,dp[i][a[i]]=true;此外狀態 dp[i][j] 可以由 dp[i1][j]dp[i1][(ja[i]+m)%m] 轉移而得,只要這兩種狀態其中任一項為真,則 dp[i][j] 也為真 。

貌似資料不算特別強,排序後多寫幾個特判其實也可以水過去(不推薦

程式碼:

/*
 * @author FreeWifi_novicer
 * language : C++/C
 */
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>

using namespace std;

#define clr( x , y ) memset(x,y,sizeof(x))
#define cls( x ) memset(x,0,sizeof(x))
#define mp make_pair
#define pb push_back
typedef long long lint;
typedef long long ll;
typedef long long LL;

const int maxn = 1e6 + 5 ;
int a[maxn] ;
bool dp[3005][3005] ;
int main(){
    //  freopen("input.txt","r",stdin);
    int n , mod ;
    while( cin >> n >> mod ){
        bool ok = false ;
        if( n >= mod ) ok = true ;
        for( int i = 1 ; i <= n ; i++ ){
            scanf( "%d" , a+i ) ;
            a[i] %= mod ;
            if( a[i] % mod == 0 ) ok = true ;
        }
        if( ok ){
            puts( "YES" ) ;
            continue ;
        }
        clr( dp , false ) ;
        for (int i = 1; i <= n ;i ++)
            dp[i][a[i]] = 1;

        for( int i = 2 ; i <= n ; i++ ){
            for( int j = 0 ; j < mod  ; j++ ){
                dp[i][j] |= dp[i-1][j] ;
                int tmp = ( j - a[i] + mod ) % mod ;
                dp[i][j] |= dp[i-1][tmp] ;
            }
        }
        if( dp[n][0] ) ok = true ;
        if(ok)
            puts( "YES" ) ;
        else
            puts( "NO" ) ;
    }
    return 0;
}

C.Vasya and Petya’s Game

題意:

輸入一個未知數n,可以詢問n是否能被某個數整除,現在告訴你n,求出最少詢問哪些數後,可以必定求出n。

思路:

看似比較難。。其實比B簡單很多。
要區分pkpk+1,唯一的辦法就是詢問能否被pk整除與能否被pk+1整除。。
所以輸出所有不超過n的 pk 即可 。

程式碼:

/*
* @author FreeWifi_novicer
* language : C++/C
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>

using namespace std;

#define clr( x , y ) memset(x,y,sizeof(x))
#define cls( x ) memset(x,0,sizeof(x))
#define mp make_pair
#define pb push_back
typedef long long lint;
typedef long long ll;
typedef long long LL;

const int maxn = 1e3 + 5 ;
bool noprime[maxn] ;
vector<int>p ;
int sieve( int n ){
    cls( noprime ) ;
    p.clear() ;
    for( int i = 2 ; i * i <= n ; i++ )
        if( !noprime[i] )
            for( int j = i * i ; j <= n ; j += i )
                noprime[j] = true ;
    for( int i = 2 ; i <= n ; i++ )
        if( !noprime[i] )
            p.pb(i) ;
    return p.size() ;
}

vector<int>ans ;
int main(){
//  freopen("input.txt","r",stdin);
    int n ;
    while( cin >> n ){
        if( n == 1 ){
            cout << 0 << endl ;
            continue ;
        }
        ans.clear() ;
        int num = sieve( n ) ;
        for( int i = 0 ; i < num ; i++ ){
            int k = p[i] ;
            while( k <= n ){
                ans.pb( k ) ;
                k *= p[i] ;
            }
        }
        cout << ans.size() << endl ;
        for( int i = 0 ; i < int( ans.size() ) ; i++ ){
            cout << ans[i] << ' ' ;
        }
        cout << endl ;
    }
    return 0;
}

D. Invariance of Tree(還沒做..

E. Points on Plane

題意:

求n個點構成的且曼哈頓距離不超過 25108 的哈密爾頓路徑

思路:

據說莫隊演算法可以搞。
但這題可以簡化下:
要保證相鄰點間的曼哈頓距離之和小於 25108 ,就是從左到右將原來的 106106 的座標系轉化成1000個 103106 的區域,相鄰區域的路徑走向一上一下即可。

程式碼:

/*
* @author FreeWifi_novicer
* language : C++/C
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>

using namespace std;

#define clr( x , y ) memset(x,y,sizeof(x))
#define cls( x ) memset(x,0,sizeof(x))
#define mp make_pair
#define pb push_back
typedef long long lint;
typedef long long ll;
typedef long long LL;

const int maxn = 1e6 + 500 ;
const int len = 1e3 ;
struct Point{
    int x , y , id ;
}p[maxn] ;
bool cmp( Point a , Point b ){
    if( a.x / len != b.x / len ) return a.x / len < b.x / len ;
    if( ( a.x / len ) & 1 ) return a.y < b.y ;
    return a.y > b.y ;
}
int main(){
//  freopen("input.txt","r",stdin);
    int n ; cin >> n ;
    for( int i = 1 ; i <= n ; i++ ){
        scanf( "%d%d" , &p[i].x ,&p[i].y ) ;
        p[i].id = i ;
    }
    sort( p + 1 , p + 1 + n , cmp ) ;
    for( int i = 1 ; i <= n ; i++ ) cout << p[i].id << ' ' ;
    return 0;
}

相關推薦

Codeforces Round #319 (Div. 2)(A,B,C,E)

Codeforces Round #319 (Div. 2) A.Multiplication Table 題意: 求m在n*n的加法表中出現了幾次 思路: 列舉1到n,累計能整除m的情況。 程式碼: /* * @aut

Codeforces Round #426 (Div. 2)A B C題+賽後小結

ase com || namespace inf exp test 鏈接 %d   最近比賽有點多,可是好像每場比賽都是被虐,單純磨礪心態的作用。最近講的內容也有點多,即便是點到為止很淺顯的版塊,刷了專題之後的狀態還是~"咦,能做,可是並沒有把握能A啊"。每場網絡賽,我似乎

Codeforces Round #475 Div. 2 A B C D

rac sca 節點 spa AR 並且 split -s using A - Splits 題意 將一個正整數拆分成若幹個正整數的和,從大到小排下來,與第一個數字相同的數字的個數為這個拆分的權重。 問\(n\)的所有拆分的不同權重可能個數。 思路 全拆成1,然後每次將2個

Codeforces Round #520 (Div. 2) A B C D

A. A Prank 題目連結:http://codeforces.com/contest/1062/problem/A 題目大意:n個數,輸入n個數,然後對於這些數,看最多能夠擦除多少個數,還能還原出原陣列。 這些數範圍:1~1000。 方法:下標相減==裡面的元素值相減則是能夠刪

Codeforces Round #259 (Div. 2) A B C 三連發

Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight

Codeforces Round #390 (Div. 2)(A,B,C(記憶化搜尋),D(貪心,優先佇列))

/* Codeforces Round #390 (Div. 2) 時間: 2017/02/16 A. Lesha and array splitting 題意:將集合分成幾個小集合,要求小集合的和不為0. 題解:遍歷過去,一直到不滿足集合並數字非0前生成一個集合 */ #

Codeforces Round #424 Div.2 A B C D E F

Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is poss

[Codeforces Round #530 (Div. 2)] A,B,C

[Codeforces Round #530 (Div. 2)] A,B,C 前言: 這是一場十分難受的cf,分數1551 → 1548,基本上算是變化不大,4min出的A,有點慢,但是考慮到題意稍微有點坑人,總的來說能夠接受,9min莽了一發B,然後就開始開C,C的做法不是特別好,

Codeforces Round #530 (Div. 2) A,B,C,D

A. Snowball 連結:http://codeforces.com/contest/1099/problem/A 思路:模擬 程式碼: #include<bits/stdc++.h> using namespace std; #define ll long long #d

Codeforces Round #350 (Div. 2) A B C D1 D2 E

A:7天內有連續5天工作2天休息,給你天數,問最少和最大可以休息的天數。 顯然(1)開始就是工作時休息最少,(2)開始是休息時休息最多。(2)先把休息的減掉變成(1)。 #include <algorithm> #include <iostream&g

codeforcesRound #522 (Div. 2) A+B+C+D

目錄 【A. Kitchen Utensils】 【B. Personalized Cup】 【C. Playing Piano】 【D. Barcelonian Distance】  【A. Kitchen Utensils】 題目連結:htt

codeforcesRound #520 (Div. 2) A+B+C+D

目錄 A - A Prank B - Math C - Banh-mi D - Fun with Integers 【A - A Prank】 題目連結:http://codeforces.com/contest/1062/problem/A 【題意】 給你一串序

Codeforces Round #416 (Div. 2) A+B

src separate not sum redo swe tput output depend A. Vladik and Courtesy 2 seconds 256 megabytes At regular competition Vl

AIM Tech Round 4 (Div. 2) A B C

can out cnblogs 並查集 logs using scan 色相 所有 A. Diversity 題意:給出一個字符串,和n,問最多改變多少個字符,使其不同字符最少為n 1 #include<bits/stdc++.h> 2 using nam

CF-Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) A,B,C

A. The King's Race 題目連結:http://codeforces.com/contest/1075/problem/A 題目大意:一個棋盤,(1,1)(n,n)分別一個點,然後給出一個目標點的座標,問誰先到(一次可以走八個方向) 水題,直接輸出: int main(

Codeforces Round #521 (Div. 3) A B C D E

A. Frog Jumping 題目連結:https://codeforces.com/contest/1077/problem/A 題目大意:t組測試資料,從0開始,向前跳a,向後跳b,跳k次,輸出最後所在的位置。 題解:大水題,直接輸出就行了 int main() { std:

Codeforces Round #520 (Div. 2)A,B

A.Prank 大意就是: 給你一個序列,讓你從這個序列中扣一段連續的數,如果你看到餘下的數仍能還原原來的序列就是對的,求最大可以扣多少個數. 思路: 首先我們扣掉的數是個連續的序列,那麼如果是1.3.5不連續任意扣掉一個不能還原,如果是連續的話比如 2.3.4就可以保留開頭結尾扣掉中間

Codeforces Round #511 (Div. 2).A. Little C Loves 3 I(水題)

A. Little C Loves 3 I time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

【題解】codeforces1047A[Codeforces Round #511 (Div. 2)]A.Little C Loves 3 I 數學知識

題目連結 Description Little C loves number «3» very much. He loves all things about it. Now he has a positive integer n. He wants to sp

Final Round (Open Div. 2)A,B,C

感覺這場的題面都好長,看的腦殼子疼(英語不好,啊我掛了 A. The King's Race 考慮對角線為分界 #include <iostream> using namespace std; int main() { long long n,x,y