素數的博士篩法(二次篩法)

素數的博士篩法(二次篩法)#define N 1<<24short p[N/2];short pri[N];void sieve(){    int i,j,k,c;    c=N>>1;    for(i=0;i<c;++i)p[i]=1;    //2x^2 = N/2估算i的上限    for(i=0;i<2048;++i)     if(p[i]) for(k=(i<<1)+3,j=k*i+i+k;j<c;j+=k) p[j]=0; 

互質 —— CF Round #146 (Div. 2)

分情況討論。相鄰兩個數必然互質,相鄰三個數構成mod3的完全剩餘系。。。  如果n為奇數..n,n-1,n-2肯定兩兩互質。  如果n是偶數,那麼就不能同時選n和n-2。。。這時候能選的最大的是n-3,但是如果n是3的倍數,n和n-3又mod3同餘,這樣只可以選n-1,n-2,n-3。。。  還要特判1和2http://codeforces.com/contest/236/problem/Chttp://codeforces.com/contest/236/submit #include<

hdu1466 計算直線的交點數//dp+set

#include<iostream>#include<stdio.h>#include<set>using namespace std;class node{public:set<int >t;};node st[21];int main(){st[1].t .insert (0);st[2].t .insert (0);st[2].t .insert (1);st[3].t .insert (0);st[3].t .insert (2);st[3

二分圖——《演算法藝術與資訊學競賽》

http://acm.timus.ru/problem.aspx?space=1&num=1155原來的題目描述:1155. TroubleduonsTime Limit: 0.5 secondMemory Limit: 16 MBArchangel of the Science is reporting:“O, Lord! Those physicists on the Earth have discovered a new elementary particle!”“No

zoj3166 Lazy Tourist//floyd求兩點間最短路

#include<iostream>#include<string.h>#include<stdlib.h>#include<stdio.h>using namespace std;#define inf 100005#define N 105int g[N][N],dist[N][N];int n,c;int cs[N];int cmp(const void *a,const void *b){return *(int *)a>*(int

貪心入門 ——HDoj 2037:今年暑假不AC。

貪心 入門http://acm.hdu.edu.cn/showproblem.php?pid=2037題目描述:今年暑假不ACTime Limit: 2000/1000 MS(Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s):17515    Accepted Submission(s): 9097Problem

hdu 1176免費餡餅 //dp

#include<iostream>#include<stdlib.h>#include<stdio.h>using namespace std;#define ma(x,y) ((x>y?x:y))int dp[11][100005],time[11][100005];int main(){int

DP——Coin Change

//http://acm.hdu.edu.cn/showproblem.php?pid=2069//白書 上 的 dp。#include <cstdio>#include <cstring>#include<algorithm>#include<iostream>using namespace std;#define MAX 10000int dp[300];int main(){ int n;// for (int i=0;i<

二分——CF154,Div.2

//http://www.codeforces.com/contest/253/problem/B//二分#include <algorithm>#include <iostream>#include <cstdio>using namespace std;int a[155660],n;int lower_bound2(int v){ int x=1; int y=n; int m;// cout<<"v is

zoj3123 Subsequence//最短序列和

毫無最佳化時,TLE, 加入二分最佳化,時間為50ms.強大的二分AC代碼:#include<stdio.h>#include<string.h>#include<iostream>using namespace std;#define N 100005int a[N];int main(){int t;cin>>t;while(t--){int n,s;int su=0;scanf("%d%d",&n,&s);for(int i=

DP——樹形DP——HDOJ1620

題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=1520 大犇解題報告:http://blog.csdn.net/woshi250hua/article/details/7641589#comments 用數組類比實現鄰接關係://http://acm.hdu.edu.cn/showproblem.php?pid=1520#include <iostream>#include <cstdio>#include

【動態規劃】廣場鋪磚

有一個 W 行 H 列的廣場,需要用 1*2小磚鋪蓋,小磚之間互相不能重疊,問有多少種不同的鋪法? 輸入資料: 只有一行 2個整數,分別為 W 和 H,(1<=W,H<=11) 輸出資料: 只有 1個整數,為所有的鋪法數。 範例: Floor.in 2 4 Floor.out 5 範例鋪法如:一道比較簡單的狀態壓縮型動態規劃。用插頭DP實現,此處略去N字……Accode:#include <cstdio>#include

產品設計體會(五三)——產品文檔與規範

幾個月來不斷的整理適合我們團隊的各種文檔,是一個非常輕量級的文檔包,這次對著理好的mindmanager圖講,分五類: Ø         需求管理類n         功能列表極其管理方法,這裡可以體會到團隊協同工具的重要,現在我們用的是office live的excel,比較簡單。n         產品的網站頁面地圖。 Ø         專案管理類n         項目Kick Off的ppt。n         專案工作書。n         項目日報。n        

【動態規劃】特別行動隊

【問題描述】 你有一支由 n 名預備役士兵組成的部隊,士兵從 1到n編號,要將他們拆分成若干特別行動隊調入戰場。出於默契的考慮,同一支特別行動隊中隊員的編號應該連續,即為形如(i, i + 1, …, i + k)的序列。 編號為 i 計程車兵的初始戰鬥力為 xi ,一支特別行動隊的初始戰鬥力 x為隊內士兵初始戰鬥力之和,即 x = xi + xi+1 + … + xi+k。 通過長期的觀察,你總結出一支特別行動隊的初始戰鬥力 x將按如下經驗公式修正為x':x' = ax2 + bx +

DP——Hdu 2602 Bone Collector

Hdu 2602 Bone Collector 非常常規的01背包問題,http://acm.hdu.edu.cn/showproblem.php?pid=2602http://blog.csdn.net/woshi250hua/article/details/7636866#include <iostream>#include <cstdio>#include <cstring>using namespace std;int v[1122], w[1100]

數學推公式——較難——Codeforces Round #187 (Div. 2)

題目連結:http://codeforces.com/contest/315/problem/CC. Sereja and Contesttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDuring the last Sereja's Codesecrof round the server crashed many times, so

Codeforces Round #181 (Div. 2) 部分解題報告

思想總結:上次rating 略微漲了一點,這次心急。連a題的範例都沒仔細查對,就wa了一次。並且老毛病,改代碼不細想。b題,並查集也搞了好久,不熟練。然後處理集合一直處於想清楚,沒想清楚的混沌狀態。然後一個條件判斷錯了。早上起來想哪裡沒處理清楚。原來是負數也能被一個數整除。沒細想。c題,據說是數位dp。不會,去年暑假集訓有一個打標題是dp。但打表ac後,就沒管了。。。要學習的東西很多啊。。。 http://www.codeforces.com/contest/300 a題水題;#include&

ZOJ 3107 Counting Squares//計算幾何

題意:按指令畫多邊形,求出裡面有多少個正方形。思路:求出面積。注意:需判斷多邊形的走向,利用叉積的正負個數。#include<iostream>#include<stdio.h>#include<math.h>#include<string.h>int dir[][4]={{0,1},{0,-1},{-1,0},{1,0}};int f(char ch ){if(ch=='U') return 0;else if(ch=='D') return 1

坑爹水題——Uva10036

題目連結:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=&problem=976&mosmsg=Submission+received+with+ID+11932248Problem B: Primary ArithmeticChildren are taught to add multi-digit

zoj 3197 Google Book//最小區間覆蓋

最悲哀的,莫過於死活不過...#include<iostream>#include<stdio.h>#include<stdlib.h>#include<string.h>using namespace std;#define N 5005class node{public:int left,right;};node st[N];int n;int cmp(const void *a,const void *b){node *c =(node *)

總頁數: 61357 1 .... 17414 17415 17416 17417 17418 .... 61357 Go to: 前往

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.