随笔分类 -  NYOJ

nanyangligong
摘要:原题链接: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 阅读(205) 评论(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 阅读(206) 评论(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 阅读(170) 评论(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 阅读(219) 评论(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 阅读(162) 评论(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 阅读(195) 评论(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 阅读(189) 评论(0) 推荐(0)
摘要:原题链接:http://acm.hdu.edu.cn/submit.php?pid=1052http://acm.nyist.net/JudgeOnline/problem.php?pid=364分析:当二者最快的马速度相同时,要凭借田忌最慢的马与大王最慢的马的速度关系来确定如何比。Tian Ji -- The Horse Racing 1 #include 2 #include 3 #include 4 using namespace std; 5 int a[1005],b[1005]; 6 int main() 7 { 8 int n,i,j,v,front,rear;long ... 阅读全文
posted @ 2013-06-04 18:11 EtheGreat 阅读(159) 评论(0) 推荐(0)
摘要:原题链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=106分析:排序加贪心。背包问题 1 #include 2 int main() 3 { 4 int n,s,m,i,j,value,temp;int str[11][2]; 5 scanf("%d",&n); 6 while(n--) 7 { 8 value=0; 9 scanf("%d%d",&s,&m);10 for(i=0;i<s;i++)11 scanf("%d%d",&st... 阅读全文
posted @ 2013-05-31 22:31 EtheGreat 阅读(154) 评论(0) 推荐(0)
摘要:原题链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=44分析:经典DP。子串和 1 #include 2 long long T,num,front,i,n,ans; 3 long long max(long long x,long long y) 4 { 5 if(x>y)return x; 6 return y; 7 } 8 int main() 9 {10 scanf("%lld",&T);11 while(T--)12 {13 scanf("%lld",&n);14 . 阅读全文
posted @ 2013-05-31 22:21 EtheGreat 阅读(128) 评论(0) 推荐(0)
摘要:原题链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=68分析:有向图。三点顺序 1 #include 2 int main() 3 { 4 int x1,y1,x2,y2,x3,y3,p;long s; 5 while(scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3)==6) 6 { 7 if(x1==0&&y1==0&&x2==0&&y2==0&&x3==0& 阅读全文
posted @ 2013-05-31 22:17 EtheGreat 阅读(122) 评论(0) 推荐(0)