07 2013 档案

摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=3466思路:贪心对当前能取的,q-p较小的优先考虑#include #include #include #include #include #include using namespace std;#define maxn 500005int dp[maxn];struct thing{ int p,q,v;}t[510];bool cmp(thing a,thing b){ return (a.q-a.p)=t[i].p;j--) if(j>=t[i].q) ... 阅读全文
posted @ 2013-07-29 15:53 over_flow 阅读(151) 评论(0) 推荐(0)
摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=2639思路:01背包 第K优解#include #include #include #include #include #include using namespace std;int N,V,K;int f[1010][35];int A[35],B[35];int v[110],w[110];int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d%d%d",&N,&V,& 阅读全文
posted @ 2013-07-29 15:21 over_flow 阅读(158) 评论(0) 推荐(0)
摘要:题目:http://poj.org/problem?id=2184负体积的01背包,将原点偏移一下,空间变大了#include #include #include #include #include #include #include #define maxn 200010using namespace std;int s[110],f[110];int dp[maxn];const int miao=100000;int main(){ int n; scanf("%d",&n); int sum=0; for(int i=1;i0) for(i... 阅读全文
posted @ 2013-07-29 14:50 over_flow 阅读(158) 评论(0) 推荐(0)
摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=2955思路:裸的01背包已知被抓的概率,因为不是相互独立的,一次被抓就不用讨论了,所以我们讨论不被抓的最大概率。#include #include #include #include #include using namespace std;double dp[10010],P,p[110];int money[110];int main(){ int t; scanf("%d",&t); while(t--) { int n; scanf("%lf%... 阅读全文
posted @ 2013-07-28 00:46 over_flow 阅读(141) 评论(0) 推荐(0)
摘要:题目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=503思路:裸的01背包#include #include #include #include #include using namespace std;#define maxn 50010int dp[maxn];int coin[110];int main(){ int t; scanf("%d",&t); while(t--) { int n; 阅读全文
posted @ 2013-07-28 00:21 over_flow 阅读(149) 评论(0) 推荐(0)
摘要:题目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=8&page=show_problem&problem=565思路:裸的01背包,输出路径,用一维数组标记的#include #include #include #include #include #include using namespace std;int minute[25];int dp[10010];int cnt[10010];int main(){ int n,m; stacks; wh 阅读全文
posted @ 2013-07-28 00:03 over_flow 阅读(131) 评论(0) 推荐(0)
摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=3826思路:如果存在某个大于10^6的质因子,那么顶多存在两个,不然就超longlong了,所以在允许的范围内解决问题还是蛮简单的#include #include #include #include #include using namespace std;#define maxn 1000010bool vis[maxn];int n_prime=0;int prime[78510];int cnt[78510];void Prime(){ memset(vis,true,sizeof(vis... 阅读全文
posted @ 2013-07-25 21:46 over_flow 阅读(198) 评论(0) 推荐(0)
摘要:题目:118A - String Task思路:water#include #include #include #include #include #include #define MAXN 100000using namespace std;char s[12]={'a','o','y','e','u','i','A','O','Y','E','U','I'};bool is_ok(char c){ f 阅读全文
posted @ 2013-07-24 17:28 over_flow 阅读(149) 评论(0) 推荐(0)
摘要:题目:158A - Next Round思路:水#include #include #include #include #include #include using namespace std;int num[51];int main(){ int n,k,x; int ans=0; cin>>n>>k; for(int i=1;i>num[i]; int tmp=k; while(tmp0) tmp--; cout<<tmp<<endl; return 0;}View Code 阅读全文
posted @ 2013-07-24 15:57 over_flow 阅读(177) 评论(0) 推荐(0)
摘要:题目:109A - Lucky Sum of Digits思路:扩展欧几里得#include #include #include #include #include #include using namespace std;long long exgcd(long long a,long long b,long long &x,long long &y){ if(b==0) { x=1; y=0; return a; } else { long long ans=exgcd(b,a%b,x,y); ... 阅读全文
posted @ 2013-07-23 09:23 over_flow 阅读(151) 评论(0) 推荐(0)
摘要:题目:A - Points on Line思路:二分找到不比当前值加差值打的最后一个数字,然后讨论#include #include #include #include #include #include using namespace std;long long node[100010];int fun(int l,int r,long long x){ if(l>=r) return l; int mid=(l+r)/2; if(node[mid]==x) return mid; if(node[mid]>n>>k; for(int... 阅读全文
posted @ 2013-07-22 22:54 over_flow 阅读(200) 评论(0) 推荐(0)
摘要:题目:171B - A star思路:递推#include #include #include #include #include #include using namespace std;int main(){ long long n; cin>>n; cout<<6*n*(n-1)+1<<endl; return 0;}View Code 阅读全文
posted @ 2013-07-22 21:51 over_flow 阅读(172) 评论(0) 推荐(0)
摘要:题目:http://codeforces.com/problemset/problem/152/C思路:标记每位出现不同字母的次数即可,然后累乘取模#include #include #include #include #include #include using namespace std;#define mod 1000000007string s[110];mapmp;int main(){ int n,m; cin>>n>>m; for(int i=0;i>s[i]; long long ans=1; for(int i=0;i<m;i++) { 阅读全文
posted @ 2013-07-22 21:40 over_flow 阅读(98) 评论(0) 推荐(0)
摘要:题目:http://codeforces.com/problemset/problem/131/C思路:打表或者直接暴力#include #include #include #include #include using namespace std;long long f[65][65];void init(){ for(int i=0;i>m>>n>>t; long long ans=0; int cnt; for(int i=4;i<=m;i++) { if(t-i<1) break; ans+=f[m][i]... 阅读全文
posted @ 2013-07-22 21:32 over_flow 阅读(137) 评论(0) 推荐(0)
摘要:题目:http://codeforces.com/problemset/problem/124/B思路:学会用while(next_permutation(...))#include #include #include #include #include using namespace std;#define inf 0xfffffffint num[10][10];int p[10];int main(){ char s; int n,k; cin>>n>>k; for(int i=0;i>s; num[i][j]=s-'0'; }... 阅读全文
posted @ 2013-07-22 21:19 over_flow 阅读(131) 评论(0) 推荐(0)
摘要:#include #include #include #include #include using namespace std;int num[55];int main(){ int n,k; cin>>n>>k; for(int i=1;i>num[i]; sort(num+1,num+n+1); int cnt=n; while(k--) { cnt--; } if(cnt>=0) cout<<num[cnt]<<" "<<num[cnt]+1<<endl; else cout< 阅读全文
posted @ 2013-07-22 16:23 over_flow 阅读(130) 评论(0) 推荐(0)
摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=1573思路:同余方程,模板#include #include #include #include #include using namespace std;long long a[11],b[11];long long exgcd(long long a,long long b,long long &x,long long &y){ if(b==0) { x=1; y=0; return a; } else { lon... 阅读全文
posted @ 2013-07-19 09:28 over_flow 阅读(214) 评论(0) 推荐(0)
摘要:题目:Prime Generator思路:分段筛素数#include #include #include #include #include #include using namespace std;#define maxn 40000int n_prime=0;bool vis[maxn];int prime[4210];bool cnt[100010];void Prime(){ memset(vis,true,sizeof(vis)); vis[0]=vis[1]=0; for(int i=2;i=l&&j<=r) cnt[j-l]... 阅读全文
posted @ 2013-07-18 20:06 over_flow 阅读(219) 评论(0) 推荐(0)
摘要:题目:Jolly Jumpers思路:标记一下就ok#include #include #include #include #include using namespace std;bool vis[3010];int main(){ int n; bool tag; while(cin>>n) { for(int i=1;i>x0; int tmp=n; tmp--; while(tmp--) { cin>>x; if(abs(x-x0)<3001) ... 阅读全文
posted @ 2013-07-18 09:36 over_flow 阅读(144) 评论(0) 推荐(0)
摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=2685思路:gcd(A^m-B^m,A^n-B^n)= A^gcd(m,n) - B^gcd(m,n) 这里特殊情况B=1#include #include #include #include #include using namespace std;long long gcd(long long a,long long b){ if(b==0) return a; return gcd(b,a%b);}long long Pow(long long a,long long b... 阅读全文
posted @ 2013-07-17 17:18 over_flow 阅读(250) 评论(0) 推荐(0)
摘要:题目:http://poj.org/problem?id=2891思路:扩展欧几里得#include #include #include #include #include using namespace std;#define maxn 100010int n;long long a[maxn],b[maxn];long long exgcd(long long a,long long b,long long &x,long long &y){ if(b==0) { x=1; y=0; return a; } else ... 阅读全文
posted @ 2013-07-17 16:31 over_flow 阅读(155) 评论(0) 推荐(0)
摘要:题目:http://acm.nefu.edu.cn/test/problemshow.php?problem_id=507思路:呵呵 三层一层一层迭代求出循环节。#include #include #include #include #include using namespace std;// 1e9+7// 222222224// 183120int main(){ long long a=0,b=1; long long mod=222222224; long long ans=1; long long c=(3*b+a)%mod; a=b; b=c;... 阅读全文
posted @ 2013-07-17 16:14 over_flow 阅读(163) 评论(0) 推荐(0)
摘要:题目:No more tricks, Mr Nanguo思路:佩尔方程,剩下的递归用矩阵快速幂做#include #include #include #include #include using namespace std;#define mod 8191struct Matrix{ int m[3][3];}D,E;void init(){ for(int i=1;i>n>>k) { if(is_sqr(n)) cout<<"No answers can meet such conditions"<<endl; else ... 阅读全文
posted @ 2013-07-16 16:33 over_flow 阅读(314) 评论(0) 推荐(0)
摘要:题目:Biorhythms思路: 扩展欧几里得#include #include #include #include #include #include #include using namespace std;int w[4]={0,23,28,33},a[4];long long exgcd(long long a,long long b,long long &x,long long &y){ if(b==0) { x=1; y=0; return a; } else { long long ans=ex... 阅读全文
posted @ 2013-07-16 15:49 over_flow 阅读(142) 评论(0) 推荐(0)
摘要:题目:http://acm.nefu.edu.cn/test/problemshow.php?problem_id=66思路:直接对10取余,剩下的化简就可以到用科学技术法表示的该数的首位#include #include #include #include #include using namespace std;int main(){ int t; scanf("%d",&t); while(t--) { long long n; scanf("%lld",&n); int ans=(int)pow(10,n*log10(n... 阅读全文
posted @ 2013-07-16 15:21 over_flow 阅读(109) 评论(0) 推荐(0)
摘要:题目:Raising Modulo Numbers思路:快速幂#include #include #include #include #include using namespace std;unsigned long long Pow(unsigned long long a,unsigned long long b,unsigned long long mod){ unsigned long long ans=1; while(b) { if(b&1) { b--; ans=(ans*a)%mod; ... 阅读全文
posted @ 2013-07-16 14:47 over_flow 阅读(112) 评论(0) 推荐(0)
摘要:题目:滑雪思路:dp#include #include #include #include #include using namespace std;#define maxn 110int vis[maxn][maxn];int num[maxn][maxn];int r,c;int move[4][2]={0,1,0,-1,1,0,-1,0};int dfs(int x,int y){ if(vis[x][y]) return vis[x][y]; int ans=0; for(int i=0;i=1&&yy>=1&xxnum[xx][yy]) ... 阅读全文
posted @ 2013-07-16 14:12 over_flow 阅读(146) 评论(0) 推荐(0)
摘要:题目:1782.The jackpot思路:最大字段和#include #include #include #include #include using namespace std;#define maxn 10010int dp[maxn],num[maxn];int main(){ int n; while(scanf("%d",&n),n) { int mx=0; memset(dp,0,sizeof(dp)); for(int i=1;i0) dp[i]=num[i]+dp[i-1]; ... 阅读全文
posted @ 2013-07-16 13:44 over_flow 阅读(180) 评论(0) 推荐(0)
摘要:题目:1396Large Caclulating Work思路:题目意思很绕,但是化简之后发现其实就是求n个数的最大公约数#include #include #include #include #include using namespace std;long long gcd(long long a,long long b){ if(b==0) return a; return gcd(b,a%b);}int main(){ int t; int cas=0; while(scanf("%d",&t),t) { int n,an... 阅读全文
posted @ 2013-07-16 13:18 over_flow 阅读(168) 评论(0) 推荐(0)
摘要:题目:1563Prime Numbers思路:素数打表+记录#include #include #include #include #include using namespace std;const int maxn =1000000 +10;bool vis[maxn];int dp[maxn];int main(){ memset(vis,true,sizeof(vis)); vis[0]=vis[1]=0; for(int i=2;i*i<maxn;i++) { if(vis[i]) for(int j=2*i;j<maxn;... 阅读全文
posted @ 2013-07-16 00:00 over_flow 阅读(198) 评论(0) 推荐(0)
摘要:题目:1650ABmod C#include #include #include #include #include using namespace std;unsigned long long multi(unsigned long long a,unsigned long long b,unsigned long long mod){ unsigned long long ans=0; while(b) { if(b&1) { b--; ans=(ans+a)%mod; } ... 阅读全文
posted @ 2013-07-15 23:44 over_flow 阅读(186) 评论(0) 推荐(0)
摘要:题目:1649Prime number or not思路:miller_rabin 大素数测试#include #include #include #include #include #include using namespace std;#define Times 10long long random(long long n){ return ((double)rand()/RAND_MAX*n+0.5);}long long multi(long long a,long long b,long long m){ long long ans=0; while(b) ... 阅读全文
posted @ 2013-07-15 23:26 over_flow 阅读(259) 评论(0) 推荐(0)
摘要:题目:1075分解素因子#include #include #include #include #include #include #include using namespace std;#define maxn 65536int vis[maxn];int prime[6543];int cnt[6543];int n_prime=0;void Prime(){ memset(vis,1,sizeof(vis)); vis[0]=vis[1]=0; for(int i=2;iq; Prime(); int t; scanf("%d",&t); wh... 阅读全文
posted @ 2013-07-15 23:24 over_flow 阅读(223) 评论(0) 推荐(0)
摘要:题目:Alice, Bob and Chocolate思路:就是找处于最中间的值,然后特别判断一下#include #include #include #include #include using namespace std;int num[100010];int main(){ int n; scanf("%d",&n); long long sum=0; for(int i=1;isum/2) { cnt=i; break; } total+=num[i]; } lo... 阅读全文
posted @ 2013-07-15 16:31 over_flow 阅读(205) 评论(0) 推荐(0)
摘要:题目:President's Office思路:水 直接用map记录一下就ok#include #include #include #include #include #include using namespace std;bool vis[110][110];char s[110][110];mapmp;int move[4][2]={1,0,-1,0,0,1,0,-1};int main(){ mp.clear(); int m,n; char boss; scanf("%d%d %c",&m,&n,&boss); memset(vis 阅读全文
posted @ 2013-07-15 16:28 over_flow 阅读(179) 评论(0) 推荐(0)
摘要:题目:Triangle呵呵 原来degenerate triangle 是小的两边之和等于第三边的情况...#include #include #include #include #include using namespace std;int seg[4];bool is_ok(int a,int b,int c){ if(a+b>c) return true; return false;;}bool judge_one(){ for(int i=0;i<4;i++) for(int j=i+1;j<4;j++) for(i... 阅读全文
posted @ 2013-07-15 14:38 over_flow 阅读(162) 评论(0) 推荐(0)
摘要:题目:Regular Bracket Sequence思路:水模拟,不要以为是那个求dp的那个 ==#include #include #include #include #include #include using namespace std;int main(){ string str; stacks; while(!s.empty()) s.pop(); cin>>str; for(int i=0;i<str.size();i++) { if(str[i]=='(') s.push(str[i]); ... 阅读全文
posted @ 2013-07-14 11:06 over_flow 阅读(151) 评论(0) 推荐(0)
摘要:题目:Center Alignment思路:模拟#include #include #include #include #include using namespace std;char s[1010][1010];int main(){ int cnt=0; while(gets(s[cnt++])) ; int mx=0; for(int i=0;i<cnt;i++) { int l=strlen(s[i]); mx=max(mx,l); } for(int i=0;i<mx+2;i++) cout<<"*... 阅读全文
posted @ 2013-07-13 15:59 over_flow 阅读(261) 评论(0) 推荐(0)
摘要:题目:Chat Servers Outgoing Traffic思路:水,map模拟#include #include #include #include #include #include #include using namespace std;mapm;int main(){ m.clear(); char s[110]; string str; int ans=0; while(gets(s)) { str=""; int l=strlen(s); if(s[0]=='+') { ... 阅读全文
posted @ 2013-07-13 13:45 over_flow 阅读(199) 评论(0) 推荐(0)
摘要:题目:http://acm.nyist.net/JudgeOnline/problem.php?pid=16思路:最长上升子序列#include #include #include #include #include using namespace std;struct node{ int x,y;}p[1010];int dp[1010];bool cmp(node a,node b){ if(a.x==b.x) return a.yp[i].y) swap(p[i].x,p[i].y); dp[i]=1; } sor... 阅读全文
posted @ 2013-07-13 11:11 over_flow 阅读(174) 评论(0) 推荐(0)
摘要:题目:http://poj.org/problem?id=1061思路:扩展欧几里得#include #include #include #include #include using namespace std;long long gcd(long long a,long long b){ if(b==0) return a; return gcd(b,a%b);}long long exgcd(long long a,long long b,long long &x,long long &y){ if(b==0) { x=1; ... 阅读全文
posted @ 2013-07-12 21:32 over_flow 阅读(171) 评论(0) 推荐(0)
摘要:题目:http://acm.nefu.edu.cn/test/problemshow.php?problem_id=2思路:水#include #include #include #include #include using namespace std;#define maxn ((1>n) { int ans=0; for(int i=3;i=2) ans++; cout<<ans<<endl; } return 0;}View Code 阅读全文
posted @ 2013-07-12 21:23 over_flow 阅读(138) 评论(0) 推荐(0)
摘要:题目:http://acm.nefu.edu.cn/test/problemshow.php?problem_id=120思路:大数测试#include #include #include #include #include #include using namespace std;#define Times 10long long random(long long n){ return ((double)rand()/RAND_MAX*n+0.5);}long long multi(long long a,long long b,long long m){ long long a... 阅读全文
posted @ 2013-07-12 21:02 over_flow 阅读(164) 评论(0) 推荐(0)
摘要:题目:思路:水#include #include #include #include #include using namespace std;int main(){ int t; cin>>t; while(t--) { long long n; cin>>n; long long ans=0; long long cnt=5; while(cnt<=n) { ans+=n/cnt; cnt*=5; } cout<... 阅读全文
posted @ 2013-07-12 20:52 over_flow 阅读(112) 评论(0) 推荐(0)
摘要:题目:http://acm.nefu.edu.cn/test/problemshow.php?problem_id=117思路:水/* 求10^n内素数的个数的位数 = log(10)(num(n))+1 num(n) = n/ln(n) num(10^n) = 10^n/(n*ln(10)) = lg(10^n) - lg(n) - lg(ln(10)) + 1 = n+1 -lg(n) - lb(ln(10))*/#include #include #include #include #include using namespace std;int main(){ ... 阅读全文
posted @ 2013-07-12 20:51 over_flow 阅读(127) 评论(0) 推荐(0)
摘要:题目:http://acm.nefu.edu.cn/test/problemshow.php?problem_id=115题意:水#include #include #include #include #include using namespace std;int main(){ long long n; while(scanf("%lld",&n)!=EOF) { if(n%12==0) cout#include #include #include #include using namespace std;#define mod 12s... 阅读全文
posted @ 2013-07-12 20:49 over_flow 阅读(214) 评论(0) 推荐(0)
摘要:题目:http://acm.nefu.edu.cn/test/problemshow.php?problem_id=109题意:判断一个数是否是素数虽然这个题给的范围比较小,但是如果范围是一个__int64内的大数的话,就用到了先筛一部分素数再判断的方法,或者直接用大数测试#include #include #include #include #include #include using namespace std;#define maxn 45000int vis[maxn];mapm;void Prime(){ m.clear(); memset(vis,1,sizeof(v... 阅读全文
posted @ 2013-07-12 20:44 over_flow 阅读(285) 评论(0) 推荐(0)

点击右上角即可分享
微信分享提示