2011年7月5日

sicily 1454. Pseudoprime numbers

摘要: #include<iostream> #include<stdio.h>#include<cmath>using namespace std;int is_prime(int x){ int m=floor(sqrt((double)x)+0.5); for(int i=2;i<=m;++i) if(x%i==0) return 0; return 1;}int power(int a,int b,int m) //快速幂取模计算 (a^b)%m{ if(a==0) return 0; else if(... 阅读全文

posted @ 2011-07-05 02:00 sysu_mjc 阅读(166) 评论(0) 推荐(0) 编辑

sicily 1513. Decoding

摘要: //要注意输出格式,先前是形成每个字母或空格都立即输出, PE 多次后发现除了最后一个是空格外,(不完全的组合或超出字母表示范围)//有可能最后第二个也是空格, "You should throw away any trailing spaces" 说明最后第二个也不能输出空格//所以要用一数组out记录编码,然后去除掉最后边的空格(无论有多少个)#include<iostream>#include<cstring>using namespace std;int vis[30][30],table[30][30];char out[100];int 阅读全文

posted @ 2011-07-05 01:55 sysu_mjc 阅读(168) 评论(0) 推荐(0) 编辑

2011年7月4日

sicily 1221. 数字游戏

摘要: //m个回合里,每个回合在n个数中选择一个ai,然后剩下的数都减去bi,求选中的ai之和的最大值//0-1背包,每个数的体积都为1,背包容量为 m //显然,如果选中的m个数已固定的话,擦去这m个数的顺序对结果有影响,很明显为最大化,应该先擦掉bi小的数,//所以事先要排好序,按bi从大到小排,靠后dp选中的数bi较小#include<iostream> //0-1背包#include<algorithm>using namespace std;struct node{ int a,b;}ans[202];bool cmp(const node& x,const 阅读全文

posted @ 2011-07-04 21:02 sysu_mjc 阅读(300) 评论(0) 推荐(0) 编辑

sicily 1034. Forest

摘要: /* 题意:有n个结点,有m条边A->B,判断是不是森林, 如果一结点有两个结点以上同时指向它,即它的入度>1, 或者有环 , 即没有根节点,则不是森林, 若是森林的话,则输出它的深度和宽度, 宽度是指结点数最多的那一层*/#include<iostream> // 求森林深度和宽度 #include<stdio.h>#include<cstring>#include <algorithm>using namespace std;#define maxn 120int g[maxn][maxn]; int in[maxn],heigh 阅读全文

posted @ 2011-07-04 18:39 sysu_mjc 阅读(356) 评论(0) 推荐(0) 编辑

sicily 1031. Campus

摘要: #include<iostream> #include<vector> #include<map> #include<queue> #include<string> #include<cstring> using namespace std; const int MAXN = 205; const int INF = 1000000; int dis[MAXN]; int n;//结点数量 typedef pair<int,int> pii; struct edge//建立边的结构体 { int v; //v表 阅读全文

posted @ 2011-07-04 18:37 sysu_mjc 阅读(307) 评论(2) 推荐(0) 编辑

sicily 1027. MJ, Nowhere to Hide

摘要: #include <iostream>#include <string>using namespace std;int main(){ int n,i,j,k;int temp;int is[20],suc1[10],suc2[10]; string str1[20],str2[20];cin>>n; do { for(i=0;i<n;i++) cin>>str1[i]>>str2[i]; for(i=0;i<n;i++)is[i]=0; k=0; for(i=0;i<n;i++) { if(is[i])contin 阅读全文

posted @ 2011-07-04 18:35 sysu_mjc 阅读(292) 评论(0) 推荐(0) 编辑

sicily 1021. Couples

摘要: #include<iostream>#include<stack>#include<map>#include<stdio.h>using namespace std;int main(){ int n, m1,m2,k; while(scanf("%d",&n)&&n) { map<int,int> m; stack<int> c; for(int i=0;i<n;i++) { scanf("%d%d",&m1,&m2); m[m1]=m 阅读全文

posted @ 2011-07-04 18:34 sysu_mjc 阅读(216) 评论(0) 推荐(0) 编辑

sicily 1007. To and Fro

摘要: #include<iostream>#include<stdio.h>using namespace std;int main(){ int column,row,length,i,time; char ch,list[100][20]; while(scanf("%d",&column),column) { scanf("\n"); length=i=0; while(scanf("%c",&ch),ch!='\n') { length++; list[(length-1)/c 阅读全文

posted @ 2011-07-04 18:33 sysu_mjc 阅读(183) 评论(0) 推荐(0) 编辑

sicily 1006. Team Rankings

摘要: //先用table[200]存储“ABCDE”到“EDCBA”所有的排列,计算每个的逆序数//比如“CDEAB”,"CA"是逆序数,则标记num[64][2]=1,其中64表示在全排列中的位置,而2的运算如下://e=table[i][j]-'A';f=table[i][k]-'A';if(e>f)num[i][e+f*5]=1;//在该例中,e=2;f=0;所以e+f*5=2;可以看出最大逆序值是"ED",e=4;f=3;则e+f*5=19;//故逆序值散落在[1,19]范围内;//接着输入n个字符串,同样地计算出 阅读全文

posted @ 2011-07-04 18:31 sysu_mjc 阅读(397) 评论(0) 推荐(0) 编辑

sicily 1011. Lenny's Lucky Lotto

摘要: #include<iostream> //AC#include<cstring>#include<stdio.h>using namespace std;long long dp[12][2002],s; //这里要注意是长整形 int main(){ int t,n,m; cin>>t; for(int id=1;id<=t;++id) { cin>>n>>m; memset(dp,0,sizeof(dp)); fill(dp[1]+1,dp[1]+m+1,1); for(int i=2;i<=n;++i) 阅读全文

posted @ 2011-07-04 18:28 sysu_mjc 阅读(295) 评论(0) 推荐(0) 编辑

导航