自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

[Q]4EchoNStef

没人能逼着你刷题,更没人能阻止你刷题

  • 博客(50)
  • 资源 (1)
  • 收藏
  • 关注

原创 1781. Knight (bfs)

#include #include #include using namespace std;queue q;int vis[520][520],dis[520][520],dx[]={-2,-2,-1,-1,1,1,2,2},dy[]={-1,1,2,-2,2,-2,1,-1};int main(){ int cases,n,sx,sy,ex,ey,s,g,t; cin>>

2012-03-26 23:14:16 583

原创 1703. Obstacle Course(最短路径bfs)

给定经过矩阵每个cell的代价,求从0,0到n-1,n-1最小代价#include #include #include using namespace std;queue q;int N,ipt[200][200],dis[200][200],dx[]={-1,1,0,0},dy[]={0,0,-1,1};void bfs(){ int t=0,s,x,y,nx,n

2012-03-26 22:29:50 572

转载 1049. Mondriaan

直接上递推公式 f[i]=3*f[i-1]+f[i-2]-f[1-3] (i>=3)通项公式为 f[i]=2*(f[0]+f[1]+...+f[n-3])+3*f[n-2]+2*f[n-1] 长度为1的区间内可能有2种情况,即两个正方形或一个长方形长度为2的区间内去掉长度为1的区间中的情况有3种情况,即上面两个正方形,下面一个长方形,上下颠倒又是一种,还有两个长方形,共三种长度

2012-03-26 17:00:40 541

原创 1692. Cover

#include using namespace std;int main(){ int m,n; while(cin>>m>>n,m||n) { if((m*n)%8==0&&n!=1&&m!=1) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0;}

2012-03-24 17:11:59 807

原创 1823. Hardest Job Ever! (dijkstra)

#include using namespace std;const int INF=999999;int n,m,adj[250][250],vis[250],dis[250];void dijkstra(int v){ for(int i=0;i<n;i++) { dis[i]=adj[v][i]; vis[i]=0; } vis[v]=1; for(int i=

2012-03-20 23:44:44 671

原创 1747. 内存使用 (类的排序)

#include #include #include using namespace std;class node{public: node(){} node(int a,int b) { r=a; s=b; } int r,s; bool operator<(const node &x)const { if(r>x.r) return true;

2012-03-19 22:14:49 914 1

转载 1327. Pinary

题目概述:将1,2,3……二进制数按字典序排成一个数列,去除所有含有‘11’元素(即相邻两位都为1)的项。剩余的项形成一个新的数列,求这个新数列的第i项是多少?思路: 用ans[i]表示长度为i的“Pinary number”共有多少个,其中ans[1]=ans[2]=1,即 1, 10, 有 ans[i] = ans[i-1] + ans[i-2] (详细证明见后面)然后用sum

2012-03-19 17:16:36 637

转载 1197. Hotel (dp,字符串模糊匹配)

动态规划。实现模糊查找的功能,稍微修改最长公共子序列的状态转移方程即可实现此功能。      设 f [ i ][ j ] 表示第一个字符串的第 i 个字符前以及第二个字符串的第 j 个字符前的所有元素是否匹配      状态转移方程:      1) 若(key[i - 1] == word[j - 1] || key[i - 1] == '?') && f[i - 1][j - 1

2012-03-18 18:31:41 634

原创 4952. Another Rock-Paper-Scissors Problem

#include #include #include #include #include using namespace std;mapm;vectorv;void ini(){ v.push_back(0); int i=1; while(pow(3.0,i)+1<=10e12) { v.push_back(pow(3.0,i)+1); i++; }}ch

2012-03-18 00:16:21 654

原创 1746. DreamingAboutCarrots

#include using namespace std;int main(){ int x1,y1,x2,y2,a,b,c,d; while(cin>>a>>b>>c>>d) { x1=(a<c)?a:c; x2=(a<c)?c:a; y1=(b<d)?b:d; y2=(b<d)?d:b; if(x1==x2) { if(y2-y1>1) co

2012-03-17 09:49:46 666

原创 2499. 平方数

#include using namespace std;int main(){ int arr[60007]={0},t,n; for(int i=1;i*i<=60000;i++) arr[i*i]=1; for(int i=1;i<=60000;i++) { if(arr[i]==0) {

2012-03-17 00:44:16 738

原创 1135. 飞越原野 (bfs) ★

#include #include #include using namespace std;int dir[4][2]={1,0,-1,0,0,1,0,-1};int n,m,d,ans,g[102][102][102],head,tail; //g(xyz)表示到(x,y)后还可以飞z步的最优解bool p[102][102],vis[102][102][102];

2012-03-16 22:22:57 1660

原创 1097. LED Modding

水,看清楚题目要求就行咯#include #include #include #include using namespace std;class R{public: string name; int resis;}arr[10001];bool cmp(R x,R y){ return x.resis<y.resis;}int main(){

2012-03-16 19:15:44 810

原创 1177. Take Your Vitamins (简单类)

#include #include #include #include using namespace std;class N{public: double a,r; string u,v; double p() { return a/r*100; } bool b() { return p()

2012-03-16 18:25:56 574

原创 1141. 猴子的争斗

求生成树的生成方法数(就是生成树的个数*生成树边数全排列)这题关键在于有个公式———— n阶完全图的生成树个数是  n^(n-2) ;A(n-1,n-1)* n^(n-2) ;#include using namespace std;int main(){ int t,ans=1; cin>>t; for(int i=t-1;i>1;i--)

2012-03-16 17:37:39 905

转载 1221. 数字游戏 (01背包)

/*状态转移方程则是:dp[j]=max(dp[j],dp[j-1]+a[i]-b[i]*(j-1))理解为对于第i个数字,当要选取j个数字时,最优结果是:不选取这个数字,从剩下的数字中再选取j个数字的最优结果;或者是选取这个数字,从剩下的数字中再选取j-1个数字的最优结果。以上两者的更优者就是最优解。如此进行下去,score[m]就是最终解。*/#include

2012-03-16 00:04:19 822

原创 1167. Anagrammatic Distanc (字符串匹配)

暴力....#include #include #include using namespace std;int main(){ int t; string s1,s2; cin>>t; cin.get(); for(int l=1;l<=t;l++) { string a,b; getline(cin,s1); getline(cin,s2

2012-03-15 18:09:47 592

原创 1318. Magic Square

#include #include using namespace std;int main(){ int n,flag=0; while(cin>>n) { if(flag!=0) cout<<endl; flag++; cout<<"n="<<n<<", sum="<<(n*n+1)/2*n<<endl; int arr[17][17]={0},num=1,i=

2012-03-15 16:58:31 676

转载 1295. 负权数

在讨论之前,先看下面几个简单问题,  很简单的,就是几个除法,模除的表达式。 在程序中求.....              15 %4 = ?              15 %-4 = ?              -15 %4 = ?              -15% -4 =?      看看结果是多少呢?          回顾一下10进制转(m =

2012-03-14 11:17:17 999

转载 1694. Spiral (找规律)

右上角的数是奇数的平方,以此边路上左下右就可以找到。 #include #include using namespace std; int n, m; void find() { int place_zero = n/2+1; int len = 1, right_up= 1; int s = 1;

2012-03-14 10:57:23 831

原创 1286. Pascal Library

水之。#include using namespace std;int main(){ int n,d,arr[107][507]; bool b[107]; while(cin>>n>>d,n||d) { for(int i=0;i<n;i++) { bool b2=true; for(int j=0;j<d;j++) {

2012-03-14 10:47:09 666

原创 1350. Piggy banks

#include #include using namespace std;int next[1000007],vis[1000007],ans,n,color,p;void search(){ for(int i=1;i<=n;i++) { if(vis[i]>0) continue; //已经访问过的 ++color; //不同颜色表示不同的环

2012-03-14 10:34:13 687

转载 1179. Extrusion (多边形面积)

利用叉乘。已知向量a,b,c,三角形的面积为(a*b+b*c+c*a)/2,(*号为叉乘,a*b=a.x*b.y-a.y*b.x)。#include#includestruct Point {double x, y;}p[500];double polyS(int n){ double s=0; for(int i=0;i<n-1;++i){ s+=p[i].x*p[

2012-03-13 23:53:38 618

原创 1321. Robot (dijkstra)

#include //优先级队列实现dijkstra算法很方便#include #include using namespace std;class Path{public: int i, j; int dist; Path( int a, int b, int c ) { i = a; j = b; dist = c; } friend bool

2012-03-12 23:37:48 731

原创 1302. Magic Square (奇数幻方,找规律)

Siamese方法构造奇数幻方。#include using namespace std;int main(){ long long t; while(cin>>t&&t) cout<<((t==1)?1:(t-1)*t/2-1)<<endl; return 0;}

2012-03-12 22:31:08 2230

转载 1114. Food Cubes (3D bfs)

#include #include const int N=102;const int nei[6][3]={ { 0, 0, 1}, { 0, 0,-1}, { 1, 0, 0}, {-1, 0, 0}, { 0,

2012-03-12 17:02:19 810

原创 1716. Houses (邻接矩阵)

水之。#include #include #include using namespace std;int main(){ int n,m; while(cin>>n>>m,n||m) { if(m==0) { cout<<0<<endl; continue; } bool arr[27][27]; int a,b,list[27]={0};

2012-03-12 16:12:29 632

转载 1444. Prime Path (bfs)

一道简单的bfs题。四位质数数每次改变一位得到另一个质数的最少步骤。//广度优先搜索#include#includeusing namespace std;const int SIZE = 10000;bool prime[SIZE];int step[SIZE];//树深度标志int base[4] = {1,10,100,1000};int main(){ for

2012-03-12 15:46:20 544

转载 1172. Queens, Knights and Pawns

记得用数组表示八方向#include #include #include using namespace std;struct node { int vis; int has; } board[1200][1200];int Q[120][2],K[120][2],P[120][2];int main(){ int row,col,q_num,k_num

2012-03-12 14:36:41 601

原创 1122. Prerequisites?

水之。#include #include #include using namespace std;int main(){ int k,m; while(cin>>k&&k) { cin>>m; string inside; set s; for(int i=0;i<k;i++) { cin>>inside; s.insert(inside);

2012-03-11 22:59:45 647

原创 1128. DICE

骰子模拟。#include #include using namespace std;int main(){ char arr[7],temp; while(cin>>arr+1) { if(arr[5]=='1'||arr[6]=='1')//首先若1在上下面,将1反转至水平面 { temp=arr[5]; arr[5]=arr[4]; arr[4]

2012-03-11 22:12:12 667

原创 1741. Jaunt around the Zhuhai Campus (梯形面积)

水题。折线定积分。#include #include using namespace std;int main(){ int t,n; cin>>t; while(t--) { cin>>n; int x,y,a,b; double area=0; cin>>a>>b; for(int i=1;i<n;i++) { cin>>x>>y; a

2012-03-11 15:52:21 700

原创 1121. Tri Tiling (dp)

/* 2*3的有3种方法.所以公式是,f(n)= 3 *f(n-2) +2( f(0)+ f(2) +...+f(n-4))解递推方程得,f(n)= 4 * f(n-2) -f(n-4)*/#include using namespace std;int arr[31],n;int main(){ arr[0]=1; arr[2]=3; for(int i=4;i<31;i+=

2012-03-11 15:35:05 1332

原创 1721. Gray code

看数点书吧,c++格式输出会超时。#include #include #include #include using namespace std;void gray(bool b[20],bool g[20],int len){ g[0]=b[0]; for(int i=1;i<len;i++) g[i]=(b[i-1]^b[i]);}void

2012-03-11 15:10:53 611

转载 1158. Pick numbers

转的模版,bfs#include #include using namespace std;int row,clo;struct node{ int x; int y; int sum;};int dx[]={0,1};int dy[]={1,0};bool check(int a,int b){ if(a>=1&&a=1&&b<=clo){ return tru

2012-03-10 10:34:56 581

原创 1624. Cryptoquote

主要是联系输出格式,代码这种的cin.get()也可以换成getchar();#include #include #include #include using namespace std;int main(){ int t; string str,s; cin>>t; for(int z=1;z<=t;z++) { cin

2012-03-09 21:05:16 715

原创 1691. Abundance

water.#include using namespace std;int main(){ int t,x,y; cin>>t; while(t--) { cin>>x>>y; int result=-999999; bool b=false; for(int i=y;i>=x;i--) { int temp=0,ti=i,j=1; for(i

2012-03-09 20:14:59 770

原创 1190. Reduced ID Numbers

暴力可以过#include #include using namespace std;sets;int arr[301],n,t;bool check(int x){ for(int i=0;i<n;i++) { if(s.count(arr[i]%x)!=0) return false; else s.insert(arr[i]%x); } return t

2012-03-09 18:30:42 834 1

原创 1199. GCD(欧拉函数)

/*令 y = gcd ( x , n ),其中 y>=m ,则有 gcd(x/y,n/y)=1 .于是对于特定的y,我们想求有多少 x 满足 gcd(x,n)=y, 只要求出有多少 x/y 小于 n/y 且与 n/y 互质——这正是欧拉函数的定义:φ(a) 表示小于a且和a互质的正整数的个数思路: 先求出 n 大于等于 m 的因子 y ,再计算 n/y 的欧拉函数,最后相加即可*/#inc

2012-03-08 23:07:50 1287 1

原创 1639. Run Length Encoding

坑爹啊有空字符串的情况,PE了好多次。#include #include #include using namespace std;int main(){ string s; while(getline(cin,s)) { if(s=="") { cout<<endl; continue; } int count=0,len=s.length(

2012-03-08 22:11:16 632

Socket(C++,基于TCP)在线实时聊天程序

Socket(C++,基于TCP)在线实时聊天程序

2013-03-11

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除