Quantcast
Channel: C++博客-Vontroy
Browsing latest articles
Browse All 30 View Live

Image may be NSFW.
Clik here to view.

POJ 1002 487-3279 字符串处理

#include <iostream>#include <string>#include <algorithm>#include <cstdio>const int maxn = 20000;const int MAXN = 100000+10;using std :: string;using std :: cout;using std ::...

View Article



Image may be NSFW.
Clik here to view.

POJ 1004 Financial Management

#include <iostream>#include <cstdio>using std :: cin;using std :: cout;using std :: endl;int main(){    double ans;    double tmp;    ans = 0;    for( int i = 0; i < 12; i++ )    {...

View Article

Image may be NSFW.
Clik here to view.

POJ 1005 I Think I Need a Houseboat

  /**//******************************************设需要n年设半圆面积为 S,半径为 rS = 50 * n;S = (PI * r * r) / 2;解得 n = (PI * r * r ) / 100;所给点到原点距离 len = sqrt( x * x + y * y );令len = r即可解出...

View Article

Image may be NSFW.
Clik here to view.

POJ 1006 Biorhythms 中国剩余定理

/**//***************************************比较经典的中国剩余定理~~使33×28被23除余1,用33×28×6=5544使23×33被28除余1,用23×33×19=14421使23×28被33除余1,用23×28×2=1288(5544×p+14421×e+1288×i)%(23×28×33)=n+dn=(5544×p+14421×e+1288×i-d...

View Article

Image may be NSFW.
Clik here to view.

POJ 1007 DNA Sorting 字符串处理|稳定排序

/**//*****************字符串处理稳定排序******************/#include <iostream>#include <algorithm>#include <string>using namespace std;struct DNA{    int pos;    int cnt;    string str;};bool...

View Article


Image may be NSFW.
Clik here to view.

HDU 1097 A hard puzzle

//找规律,每4个数循环一次#include <iostream>#include <cstdio>using namespace std;int main(){    long long a, b;    int ans[5];    while(cin >> a >> b)    {        if( b == 0 )        {...

View Article

Image may be NSFW.
Clik here to view.

HDU 3661 Assignments-2010 Harbin Regional

Assignments Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 252    Accepted Submission(s): 125 Problem Description In a factory, there are N...

View Article

Image may be NSFW.
Clik here to view.

HDU 2734 Quicksum 简单字符串处理

Quicksum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 492    Accepted Submission(s): 408 Problem Description A checksum is an algorithm that...

View Article


Image may be NSFW.
Clik here to view.

POJ 1269 Intersecting Lines 判断直线相交并求交点

Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4260 Accepted: 2049 Description We all know that a pair of distinct points on a plane defines a line and that a pair of...

View Article


Image may be NSFW.
Clik here to view.

POJ 2653 Pick-up sticks 判断线段相交

Pick-up sticks Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 4189 Accepted: 1501 Description Stan has n sticks of various length. He throws them one at a time on the floor in a random way....

View Article

Image may be NSFW.
Clik here to view.

HDU 1010 Tempter of the Bone

#include <iostream>#include <cstdio>#include <cmath>const int maxn = 10;using namespace std;bool escape;char map[maxn][maxn];int dir[4][2] = {{-1,0}, {1,0}, {0,-1}, {0,1}};int n, m,...

View Article

Image may be NSFW.
Clik here to view.

HDU 1198 Farm Irrigation

#include<iostream>using namespace std;int bin[2500];int find(int x){return x==bin[x]?x:find(bin[x]);}void merge(int x,int y){    x=find(x);    y=find(y);    if(x!=y) bin[x]=y;}int main(){    int...

View Article

Image may be NSFW.
Clik here to view.

POJ 1611 The Suspects

#include <iostream>#include <cstdio>const int maxn = 30000 + 5;using namespace std;int father[maxn],rank[maxn];void init( int n ){    for ( int i = 0; i < n; i++)    {        father[i] =...

View Article


Image may be NSFW.
Clik here to view.

POJ 3264 Balanced Lineup

#include <iostream>#include <cstdio>#include <algorithm>const int MY_MAX = -99999999;const int MY_MIN = 99999999;using namespace std;struct CNode{    int R, L;    int nMax, nMin;...

View Article

Image may be NSFW.
Clik here to view.

POJ 3468 A Simple Problem with Integers

#include <iostream>#include <cstdio>using namespace std;struct CNode{    int L, R;    CNode * pLeft, * pRight;    long long nSum, Inc;};CNode Tree[1000000];int nCount = 0;void BuildTree(...

View Article


Image may be NSFW.
Clik here to view.

POJ 2488 A Knight's Journey ----- DFS

#include <stdio.h>#include <string.h>const int maxn = 50;int b[8]={-2, -2, -1, -1, 1, 1, 2, 2},a[8]={-1, 1, -2, 2, -2, 2, -1, 1};bool check[maxn][maxn], flag;int ansx[maxn], ansy[maxn];int...

View Article

Image may be NSFW.
Clik here to view.

HDU 1316 How Many Fibs?

比较水的大数。。。代码: import java.util.*;import java.math.*;public class Main{    public static void main( String args[] )    {        Scanner in = new Scanner( System.in );        int cnt = 0;...

View Article


Image may be NSFW.
Clik here to view.

求两个或N个数的最大公约数(gcd)和最小公倍数(lcm)的较优算法

求两个或N个数的最大公约数(gcd)和最小公倍数(lcm)的较优算法 //两个数的最大公约数--欧几里得算法int gcd(int a, int b){     if (a < b)          swap(a, b);     if (b == 0)           return a;      else            return gcd(b,...

View Article

Image may be NSFW.
Clik here to view.

HDU 1018 Big Number

斯特灵公式是一条用来取n阶乘近似值的数学公式。一般来说,当n很大的时候,n阶乘的计算量十分大,所以斯特灵公式十分好用,而且,即使在   n很小的时候,斯特灵公式的取值已经十分准确。 公式为: 这就是说,对于足够大的整数n,这两个数互为近似值。更加精确地: 或者:     Big Number Time Limit: 20000/10000 MS (Java/Others)    Memory...

View Article

Image may be NSFW.
Clik here to view.

组合数学常用公式及算法

     摘要: /**//**********************************************1. C(m,n)=C(m,m-n)2. C(m,n)=C(m-1,n)+C(m-1,n-1)derangement D(n) = n!(1 - 1/1! + 1/2! - 1/3!&nb...  阅读全文Vontroy 2010-10-02 14:25 发表评论

View Article

Image may be NSFW.
Clik here to view.

数论及数学常用知识代码

     摘要: //数论模板#include<iostream>#include<cmath>using namespace std;//辗转相除法求最大公约数long gcd(long a, long b){     if(b==0)   &nbsp...  阅读全文Vontroy 2010-10-02 14:28 发表评论

View Article


Image may be NSFW.
Clik here to view.

HDU 1788 Chinese remainder theorem again

/**//**********************************N % MI = MI - a因为 a < MI原式等价于 (N + a) % MI = 0所以此题为求 M0 到 MI 的最小公倍数(注意精度问题,用__int64)***********************************/#include <iostream>#include...

View Article


Image may be NSFW.
Clik here to view.

POJ 1458 Common Subsequence

#include <iostream>  #include <cstdio>  #include <string>  using namespace std;  const int maxn = 301;  string str1, str2;  int main()  {      while( cin >> str1 >> str2 )...

View Article

Image may be NSFW.
Clik here to view.

HDU 1056 HangOver

#include <iostream>#include <cstdio>using namespace std;int main(){    double len;    double tmp;    int ans;    while( cin >> len, len )    {        tmp = 0;        ans = 1;...

View Article

Image may be NSFW.
Clik here to view.

字典树(Trie树)

如图,每条路径上保存一个字母,从根节点开始进行dfs,每遍历到一个标记节点(图中的红点),从根节点到当前节点路径上所有字母连起来即为一个单词上图中存储了 abc, abcd, b, bcd, efg, hij.对于Trie树主要有三种操作:新建一个结点插入一个单词在trie树中查找单词trie树中每次插入一个结点的时间复杂度是 O( strlen( str ) )建立trie树的时间复杂度为 O(...

View Article


Image may be NSFW.
Clik here to view.

POJ 2488 A Knight's Journey (DFS)

输入一个棋盘 ( p × q ),从任意点开始,每次走日子格,求能走遍每个点的序列,以Sample中给出的样式按字典序输出,如果得不到这样的序列输出impossible由于要按字典序输出,所以优先访问坐标较小的点,第一次得到的序列就是所求结果#include <iostream>#include <cstdio>#include <cstring>#include...

View Article

Image may be NSFW.
Clik here to view.

ACM中Java的应用

先说一下Java对于ACM的一些优点吧:(1) 对于熟悉C/C++的程序员来说Java 并不难学,两周时间基本可以搞定一般的编程,再用些时间了解一下Java库就行了。Java的语法和C++非常类似,可以说是C++的升级版,只是更加强调面向对象思想而已。(个人见解。。。) (2)...

View Article

Image may be NSFW.
Clik here to view.

POJ 1001 Exponentiation

Exponentiation Time Limit: 500MS Memory Limit: 10000K Total Submissions: 68964 Accepted: 16146 Description Problems involving the computation of exact values of very large magnitude and precision are...

View Article

Image may be NSFW.
Clik here to view.

ACM初学经典题(字符串处理+对字符串的排序与检索)

输入一个字典(用******结尾),然后再输入若干单词。每输入一个单词w,你都需要在字典中找出所有可以用w的字母重排后得到的单词,并按照字典序从小到大的顺序在一行中输出(如果不存在,输出:(  )输入单词之间用空格或空行隔开。注意,字典中的单词不一定按字典排列。样例输入: tarp given score refund only trap work earn course pepper...

View Article



Image may be NSFW.
Clik here to view.

POJ 2528 Mayor's posters

#include <iostream>#include <algorithm>#include <math.h>using namespace std;int n;struct CPost{    int L,R;};CPost posters[10100];int x[20200];int hash[10000010];struct CNode {    int...

View Article
Browsing latest articles
Browse All 30 View Live


Latest Images

Vimeo 10.7.0 by Vimeo.com, Inc.

Vimeo 10.7.0 by Vimeo.com, Inc.

HANGAD

HANGAD

MAKAKAALAM

MAKAKAALAM

Doodle Jump 3.11.30 by Lima Sky LLC

Doodle Jump 3.11.30 by Lima Sky LLC