- 博客(53)
- 收藏
- 关注
原创 Codechef Little Elephant and Painting (期望+动态规划)
f[i][j]表示上色i #include#include#includeusing namespace std;int read(){ int x=0,f=1;char ch=getchar(); while(ch'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-
2014-10-31 22:28:48 243
原创 3251: 树上三角形
#include#include#include#define ll long longusing namespace std;int read(){ int x=0,f=1;char ch=getchar(); while(ch'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+c
2014-10-31 20:55:27 226
原创 1914: [Usaco2010 OPen]Triangle Counting 数三角形 (计算几何)
先极角排序,对于某个点x,其与原点连线所在直线将平面划分为两部分,若一个部分有t个点,在这t个中任取2个与x显然不构成黄金三角形,画图可知对于每个点只统计某个方向的半平面内的点就能不重不漏。具体可以用一个指针旋转半平面。#include#include#include#include#define pi acos(-1.0)using namespace std;struct P{
2014-10-30 16:27:51 333
原创 Incr (LIS)
#include#includeusing namespace std;int n,ans,a[100010],b[100010];int main(){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]),a[i]-=i; for(int i=1;i<=n;i++){ in
2014-10-30 14:56:30 213
原创 Graph (dfs)
#include#includeusing namespace std;struct edge{ int to,next;}e[200001];int n,m,cnt,now,head[200001],f[200001];bool vis[200001];void ins(int u,int v){ e[++cnt]=(edge){v,head[u]};head[u]
2014-10-30 14:10:11 164
原创 【NOIP模拟赛】买汽水 (dfs+set)
#include#include#includeusing namespace std;set q;int n,m,tot,ans,a[45];bool flag;void dfs(int x,int sum){ if(sum>m)return; if(x==tot){ if(!flag)q.insert(sum); else{ set::iterator t=q.
2014-10-29 21:34:49 340
原创 【noip模拟赛】时间与空间之旅
#include #include #include #include #define inf 1000000000using namespace std;int T,n,m,cnt,ans,mid,head[105],d[105],q[105];bool mark[105],con[105];struct edge { int to,next,v;} e[200005]
2014-10-28 16:59:48 229
原创 Vijos P1781 同余方程 (exgcd)
#include#includeusing namespace std;int a,b,x,y;void exgcd(int a,int b){ if(!b){x=1,y=0;return;} exgcd(b,a%b); int t=x;x=y;y=t-a/b*y;}int main(){ cin>>a>>b; exgcd(a,b); w
2014-10-27 19:53:30 199
原创 Vijos P1753 HackSon的趣味题 (GCD)
#include#includeusing namespace std;int n,a0,a1,b0,b1,tot,pri[100001];bool pd[100001];long long ans=0;void getprime() { for(int i=2; i<=40000; i++) { if(!pd[i])pri[++tot]=i;
2014-10-27 19:50:39 242
原创 ZOJ 1577 GCD & LCM (GCD)
考虑p=mx,q=nx。gcd(p,q)=x意味着gcd(m,n)=1。[p,q]=y=p*q*x意味着m*n=y/x所以只要找到所有的m、n,满足(m,n)=1,m*n=y/x即可。枚举就可以过。也可以计算y/x质因数的种类t,则答案就是2^t。
2014-10-26 21:03:09 261
原创 2430: [Poi2003]Chocolate (贪心)
从大到小取最优。#include#include#includeusing namespace std;inline int read() { int x=0,f=1; char ch=getchar(); while(ch'9') { if(ch=='-')f=-1; ch=getchar(); } while(
2014-10-25 10:53:29 472
原创 2016: [Usaco2010]Chocolate Eating (二分法,贪心)
二分最小快乐值后判定。#include#include#define ll long longusing namespace std;ll read() { ll x=0,f=1; char ch=getchar(); while(ch'9') { if(ch=='-')f=-1; ch=getchar(); }
2014-10-25 10:52:46 306
原创 Codechef It Is Axis Time
#include#include#include#define ll long longusing namespace std;char ch[1000001];int T,n;ll all() { ll ans=(ll)n*((n-1)/2); if(n%3==0)ans-=n/3*2; return ans;}ll del() { ll ans
2014-10-24 22:05:13 164
原创 Codechef Party Mystery
#include#includeusing namespace std;int t,a,b;int gcd(int a,int b){ return b==0?a:gcd(b,a%b);}int main(){ scanf("%d",&t); while(t--){ scanf("%d%d",&a,&b); printf("%d\
2014-10-24 18:51:26 209
原创 3732: Network (树上倍增)
#include #include #include #define inf 1000000000using namespace std;inline int r(){ int x=0,f=1;char ch=getchar(); while(ch'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9')
2014-10-19 19:06:12 160
原创 1637: [Usaco2007 Mar]Balanced Lineup (前缀和)
#include#include#include#includeusing namespace std;const int add=50000;int n,ans,s[50001],pre[100001];pair a[50001];inline int read(){ int x=0,f=1;char ch=getchar(); while(ch'9'){if(c
2014-10-19 19:05:12 270
原创 1635: [Usaco2007 Jan]Tallest Cow 最高的牛 (差分序列)
#include#includeusing namespace std;struct que{ int l,r;}q[20001];inline bool cmp(que a,que b){ return a.l<b.l||(a.l==b.l&&a.r<b.r);}int n,I,h,r,sum,a[100001];int main(){ scanf("%d%d%d%d",&
2014-10-19 19:04:09 265
原创 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区 (暴力)
#include#include#includeusing namespace std;const int dx[4]={-1,1,0,0},dy[4]={0,0,1,-1};int d[60][60],s[80],q[80],ans;bool mp[60][60];char ch[100];bool jud(){ memset(d,0,sizeof(d)); int nx[8
2014-10-19 19:03:13 236
原创 1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典 (动态规划)
#include#include#include#includeusing namespace std;int n,l,len[605],f[605];char str[605],ch[605][30];inline int cal(int x,int len,int y){ int tot=0; int l1=x,l2=1; while(l1<=l){
2014-10-19 19:01:55 192
原创 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 (凸包)
#include#include#include#include#define ll long long using namespace std;struct P{ int x,y;}p[5005],s[5005];double ans;int n,top;inline int read(){ int x=0,f=1;char ch=getchar(); wh
2014-10-19 18:58:52 178
原创 1641: [Usaco2007 Nov]Cow Hurdles 奶牛跨栏 (Floyd)
#include#include#define inf 100000000using namespace std;inline int read(){ int x=0,f=1;char ch=getchar(); while(ch'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch
2014-10-18 19:04:37 255
原创 1135: [POI2009]Lyz (线段树)
#include#includeusing namespace std;const int N=800001;int n,m,k,d,ls[N],rs[N];long long mx[N],sum[N],lmx[N],rmx[N];inline int read(){ int x=0,f=1;char ch=getchar(); while(ch'9'){if(ch==
2014-10-18 19:03:05 420
原创 1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典 (动态规划)
#include#include#include#includeusing namespace std;int n,l,len[605],f[605];char str[605],ch[605][30];inline int cal(int x,int len,int y){ int tot=0; int l1=x,l2=1; while(l1<=l){
2014-10-18 19:01:18 205
原创 1649: [Usaco2006 Dec]Cow Roller Coaster (动态规划)
#include #include #include #include using namespace std;inline int read(){ int x = 0, f = 1; char ch = getchar(); while (ch '9'){ if (ch == '-') f = - 1;
2014-10-18 19:00:09 379
原创 3297: [USACO2011 Open]forgot (动态规划)
#include#include#includeusing namespace std;string a[1005],f[1005];int n,p,l[1005];char ch[1005];inline int read(){ int x=0,f=1;char ch=getchar(); while(ch'9'){if(ch=='-')f=-1;ch=getcha
2014-10-18 18:59:58 294
原创 1628: [Usaco2007 Demo]City skyline (单调栈)
#include#include#includeusing namespace std;inline int read(){ int x=0,f=1;char ch=getchar(); while(ch'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
2014-10-18 18:59:10 224
原创 1109: [POI2007]堆积木Klo (LIS)
#include#include#includeusing namespace std; inline int read(){ int x=0,f=1;char ch=getchar(); while(ch'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getc
2014-10-18 18:58:54 387
原创 1119: [POI2009]SLO (置换群)
#include#include#include#include#define ll long longusing namespace std;inline int read(){ int x=0,f=1;char ch=getchar(); while(ch'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&c
2014-10-18 18:58:08 318
原创 1131: [POI2008]Sta (树形DP)
#include#includeusing namespace std;int n,cnt,head[1000001],deep[1000001],size[1000001],ans;long long f[1000001];struct edge{ int to,next;}e[2000001];void ins(int u,int v){ e[++cnt]=(edge){v,
2014-10-18 18:56:08 204
原创 1683: [Usaco2005 Nov]City skyline 城市地平线 (单调栈)
#include#include#includeusing namespace std;inline int read(){ int x=0,f=1;char ch=getchar(); while(ch'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
2014-10-18 18:55:53 212
原创 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会 (强联通分量)
#include#includeusing namespace std;const int N=10001;struct edge{ int to,next;}e[50001];int n,m,cnt,tot,top,ans,ind,head[N],dfn[N],low[N],size[N],q[N];bool inq[N];inline void ins(int u,int v
2014-10-18 18:54:51 248
原创 1652: [Usaco2006 Feb]Treats for the Cows (区间DP)
#include#includeusing namespace std;int n,a[2005],f[2005][2005];void dp(int i,int j){ if(i==j){f[i][i]=a[i]*n;return;} if(!f[i+1][j])dp(i+1,j); if(!f[i][j-1])dp(i,j-1); f[i][j]=max(f[i][j],f[i
2014-10-18 18:54:13 194
原创 1697: [Usaco2007 Feb]Cow Sorting牛排序 (置换群)
#include#include#include#includeusing namespace std;inline int read(){ int x=0,f=1;char ch=getchar(); while(ch'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0'
2014-10-18 18:53:54 196
原创 1650: [Usaco2006 Dec]River Hopscotch 跳石子 (二分法)
#include#include#includeusing namespace std;int L,n,m,ans,a[50005];bool jud(int x){ int tot=0; if(tot>m)return 0; int last=0; for(int i=1;i<=n;i++) if(a[i]-a[last]<x){ tot++; if(tot>m
2014-10-18 18:53:01 229
原创 1132: [POI2008]Tro (叉积)
#include#include#includeusing namespace std;struct P{ int x,y;}p[3005],t[3005];int n,sumx,sumy;long long ans;inline bool operator<(P a,P b){ return a.y<b.y||(a.y==b.y&&a.x<b.x);} inline l
2014-10-18 18:51:34 209
原创 1124: [POI2008]枪战Maf (DFS)
#include#includeusing namespace std;const int maxn=1000001;int n,sum,ans1,ans2,to[maxn],d[maxn];bool vis[maxn];void dfs(int x){ vis[x]=1;sum++; if(!vis[to[x]])dfs(to[x]);}void dfs2(int x,boo
2014-10-18 18:50:55 274
原创 1642: [Usaco2007 Nov]Milking Time 挤奶时间 (动态规划)
#include#include#includeusing namespace std;struct data{ int l,r,v;}a[1001];inline bool cmp(data a,data b){ return a.l<b.l;}int n,m,r,ans,f[1001];int main(){ scanf("%d%d%d",&n,&m,&r); for
2014-10-18 18:48:25 238
原创 1106: [POI2007]立方体大作战tet (树状数组)
#include#includeusing namespace std;int n,ans,v[200001],f[200001];void ins(int x,int val){ for(int i=x;i<=n;i+=i&(-i)) v[i]+=val;}int get(int x){ int res=0; for(int i=x;i>0;i-=i&(-i)) res
2014-10-18 18:47:47 264
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人