摘要: 原题链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=139分析:cantor展开,康托展开用于计算一个排列的序数。公式为: X=a[n]*n!+a[n-1]*(n-1)!+...+a[2]*2!+a[1]*1!+a[0]*0!;0#includeusing namespace std;char s[15];long long fac[15];void F(){ fac[0]=1;fac[1]=1; for(int i=2;i<=12;i++) fac[i]=fac[i-1]*i;}int main(){ int T... 阅读全文
posted @ 2013-07-19 20:45 EtheGreat 阅读(189) 评论(0) 推荐(0) 编辑
摘要: 原题链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=333分析:直接套用欧拉公式即可!mdd的烦恼 1 #include 2 #include 3 #include 4 #include 5 #define maxn 65545 6 using namespace std; 7 int flag[maxn]={0}; 8 int prime[maxn]; 9 int cnt;10 void selPrime()11 {12 cnt=0;13 for(int i=2;i1)res*=n-1;38 return res... 阅读全文
posted @ 2013-07-19 17:50 EtheGreat 阅读(197) 评论(0) 推荐(0) 编辑
摘要: 原题链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=7分析:x与y分开考虑,分别排序,邮局定在最中间的两个数之间就可以了。街区最短路径问题 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 int x[25],y[25]; 7 int main() 8 { 9 int T,m;10 scanf("%d",&T);11 while(T--)12 {13 scanf("%d",&m);14 for.. 阅读全文
posted @ 2013-07-19 15:20 EtheGreat 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 原题链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=703分析:先考虑不受限制的情况,此时共可以修n*(n-1)/2条隧道;所有的place组成一个多边形,多边形内部的三角形共有n*(n-1)/2个,考虑限制条件,那么每两个相邻的三角形组成的四边形的对角线应该删除,共ceiling[n*(n-2)/4]条边;所以答案就是n*n/4.另解:dp[i]=i*(i-1)/2-dp[i-1];理解:i*(i-1)/2=i+(i-1)*(i-2)/2,那么(i-1)*(i-2)/2-dp[i-1]就表示前一个不满足限制条件的个数,当增加一个点时,就 阅读全文
posted @ 2013-07-19 14:41 EtheGreat 阅读(206) 评论(0) 推荐(0) 编辑
摘要: 原题链接:http://acm.uestc.edu.cn/problem.php?pid=1369&cid=192分析:DP,dp[i][0]表示第i个人不是lover时的最小值,dp[i][1]表示是的情况.I'm Hungry 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #define maxn 100005 8 using namespace std; 9 int num[maxn],dp[maxn][2];10 int main()11 {12 int T,n,cas=1;13 阅读全文
posted @ 2013-07-17 21:42 EtheGreat 阅读(191) 评论(0) 推荐(0) 编辑
摘要: 求余数原题链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=205 1 #include 2 #include 3 #include 4 #define mod 10003 5 using namespace std; 6 char num[1000005]; 7 int main() 8 { 9 int m;10 scanf("%d",&m);11 while(m--)12 {13 scanf("%s",num);14 int len=strlen(num),ans=0;15... 阅读全文
posted @ 2013-07-08 20:08 EtheGreat 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 最大素因子原题链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=520分析:先筛素数,同时记录下素数的序号,然后质因数分解。 1 2 #include 3 #include 4 #include 5 #define maxn 1000005 6 using namespace std; 7 int cnt,num; 8 long long n; 9 bool flag[maxn]={0};10 int prime[maxn];11 int count[maxn]={0};12 int por[maxn];13 int cpor[maxn.. 阅读全文
posted @ 2013-07-08 18:20 EtheGreat 阅读(188) 评论(0) 推荐(0) 编辑
摘要: 数的长度原题链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=69分析:先看看求n!的朴素算法,用大整数乘法来实现。 1 #include 2 #include 3 #include 4 using namespace std; 5 int wei[1000000]; 6 int main() 7 { 8 int t,n; 9 scanf("%d",&t);10 while(t--)11 {12 memset(wei,0,sizeof(wei));13 int cnt=0;14... 阅读全文
posted @ 2013-07-08 17:12 EtheGreat 阅读(177) 评论(0) 推荐(0) 编辑
摘要: 原体连接:http://acm.uestc.edu.cn/problem.php?pid=1237分析:质因子单增;在寻找下一个质因子时,从前一个开始。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 int isprime(int s,int n) 7 { 8 int i; 9 for(i=s;i2)31 for(int i=3;;)32 {33 if(n==1)break;34 if(n%i==0)35 ... 阅读全文
posted @ 2013-06-22 19:35 EtheGreat 阅读(195) 评论(0) 推荐(0) 编辑
摘要: 原题链接:http://www.acm.uestc.edu.cn/problem.php?pid=1005分析:判断有无"no"即可。点球大战(penalty) 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 char str[105]; 6 int isOK(char *str) 7 { 8 int len=strlen(str); 9 if(str[len-8]==' '&&str[ 阅读全文
posted @ 2013-06-11 00:27 EtheGreat 阅读(173) 评论(0) 推荐(0) 编辑