随笔分类 - 刷题之--CDOJ
摘要:原题链接:http://acm.uestc.edu.cn/problem.php?pid=1141分析:运用欧拉函数可解此题。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #define LL long long12 using namespace std;13 int T;14 int n;15 int gcd(int a,int b)16 {17 if(b==0)return a;18...
阅读全文
摘要:题目:A Coin Problem原题链接:http://acm.uestc.edu.cn/problem.php?pid=1468分析:满足裴波纳契数列,打表找周期。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 #define mod 10000 8 int dp[15005]; 9 void F(int n)10 {11 dp[0]=1;dp[1]=2;12 for(int i=2;i<=n;i++)13 dp[i]=(dp[i-1]+dp[i-2])...
阅读全文
摘要:题目:Easy math原题链接:http://acm.uestc.edu.cn/problem.php?pid=1548分析:费马小定理的应用。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 #define LL long long 7 const LL mod=1000000007; 8 LL pow_mod(LL a,LL b,LL m) 9 {10 if(b==0)return 1%m;11 LL temp=pow_mod(a,b>>1,m);12 temp=temp*t...
阅读全文
摘要:原题链接:分析:求最小周期的应用。 1 #include 2 #include 3 #include 4 #include 5 #define maxn 1005 6 using namespace std; 7 char s[maxn]; 8 int next[maxn],len; 9 void get_next()10 {11 int i=0,j=-1;len=strlen(s);12 next[0]=-1;13 while(i<len)14 {15 if(j==-1||s[i]==s[j]){16 i++,j++;1...
阅读全文
摘要:原题链接:http://acm.uestc.edu.cn/problem.php?pid=1655分析:注意可能会反向。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define maxn 1005 7 #define inf 0x7fffffff 8 using namespace std; 9 int l[maxn],r[maxn];10 int dis1[maxn];//clockwise11 int dis2[maxn];//ante-clockwise12 int ans[maxn];13 int main()1
阅读全文
摘要:原题链接:http://acm.uestc.edu.cn/problem.php?pid=1300分析:dp,最长公共上升子列。对于两个序列num1[maxn],num2[maxn]:如果num1[i]==num2[j],dp[i][j]=max(dp[i][k])+1;(knum2[k]).否则dp[i][j]=dp[i-1][j]. 1 #include 2 #include 3 #include 4 #include 5 #define maxn 1005 6 using namespace std; 7 int n1,n2,ans; 8 int num1[maxn],num2[maxn
阅读全文
摘要:原题链接:http://acm.uestc.edu.cn/problem.php?pid=1730分析:线段树单点更新,区间求和。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define maxn 500005 7 #define mod 1000007 8 using namespace std; 9 int sum[maxn>1;19 build(l,m,rt>1;30 if(ii>1;38 int res=0;39 if(L=m+1)res^=get_sum(L,R,m+1,r,rt...
阅读全文
摘要:原题链接:http://acm.uestc.edu.cn/problem.php?pid=1727分析:用 l[i] 记录第 i 层楼有多少物品需要往上继续搬运,如果某层楼没有物品,但是更上面还有,则仍需要往上走,所以需要+1. 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define maxn 111 7 #define mod 1000007 8 using namespace std; 9 int l[maxn];10 int main()11 {12 int n,cas=1,s,t,rig;13 w...
阅读全文
摘要:原题链接:http://www.acm.uestc.edu.cn/problem.php?pid=1267分析:此题麻烦之处在于要输出最小最长上升子序列,关键在于如何解决最小这个问题.我的做法是从最后一个数开始往前扫描,同时另开一重循环,从该数num[i]前一个往前扫描,即j=i-1~0.如果num[j] 2 using namespace std; 3 int num[1005]; 4 int dp[1005]; 5 int nxt[1005]; 6 int main() 7 { 8 int T; 9 scanf("%d",&T);10 while(T--)11
阅读全文
摘要:原体连接: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 ...
阅读全文
摘要:原题链接: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[
阅读全文
摘要:原题链接:http://www.acm.uestc.edu.cn/problem.php?pid=1735考试松松过 1 #include<cstdio> 2 using namespace std; 3 int main() 4 { 5 long long n,product;int ans[20]; 6 while(scanf("%lld",&n)!=EOF) 7 { 8 product=(n+1)*(3*n+2)/2; 9 int i=0;10 while(product)11 {12 ...
阅读全文
摘要:原题链接:http://acm.uestc.edu.cn/problem.php?pid=1012分析:dp[v]表示可以使用的钱为v时实际上用的钱。饭卡(card) 1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<functional> 5 #include<cstring> 6 using namespace std; 7 int m,n,i,v,price[1001],dp[1001]; 8 int main() 9 {10 whi
阅读全文
摘要:原题链接:http://acm.uestc.edu.cn/problem.php?pid=1020分析:按升序排序即可。Vote 1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<functional> 5 using namespace std; 6 int voter[105]; 7 int main() 8 { 9 int n,ans;10 while(scanf("%d",&n)==1)11 {12 if(n==0)
阅读全文
摘要:原题链接:http://acm.uestc.edu.cn/problem.php?pid=1043输出前m大的数据 1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<functional> 5 using namespace std; 6 int queue[1000005]; 7 int main() 8 { 9 int n,m,k;10 while(scanf("%d%d",&n,&m)!=EOF)11 {12
阅读全文
摘要:原题链接:http://acm.uestc.edu.cn/problem.php?pid=1047Cake 1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 int main() 5 { 6 long long t,n,m; 7 scanf("%lld",&t); 8 while(t--) 9 {10 scanf("%lld%lld",&n,&m);11 printf("%lld\n",n*m-1);12 }
阅读全文
摘要:http://acm.uestc.edu.cn/problem.php?pid=1023
阅读全文
摘要:原题链接:http://acm.uestc.edu.cn/problem.php?pid=1034锥形之阵 1 #include<stdio.h> 2 int main() 3 { 4 int t,n,i; 5 scanf("%d",&t); 6 while(t--) 7 { 8 scanf("%d",&n); 9 for(i=1;(i+1)*(i+1)/4<=n;i=i+2);10 i=i-2;11 printf("%d\n",(i+1)*(i+1)/4);12 }13 retur...
阅读全文
摘要:原题链接:http://acm.uestc.edu.cn/problem.php?pid=1060分析:画出图形,分三种情况找公式。锥形之阵之变阵 1 #include<stdio.h> 2 int main() 3 { 4 int t,n,k;long m; 5 scanf("%d",&t); 6 while(t--) 7 { 8 scanf("%d",&n); 9 k=n/3;10 if(n%3==0)m=3*k*(k+1)/2-k;11 else if(...
阅读全文
摘要:原题链接:http://acm.uestc.edu.cn/problem.php?pid=1256分析:能被11整除的数具有什么特性呢?原来是奇数位与偶数位之差的绝对值是11的倍数。能被3和11整除吗 1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 int t,s,s1,s2,s3,i; 6 char a[210]; 7 scanf("%d",&t); 8 while(t--) 9 {10 s=s1=s2=0;11 scanf("%s",a);12 .
阅读全文

浙公网安备 33010602011771号