- 博客(381)
- 收藏
- 关注
转载 Arduino 发射和接收红外线
//学号后两位26#define com_hear 2#define com_sound 3#define com_speak 4void setup() { pinMode(com_sound, OUTPUT); pinMode(com_speak, OUTPUT); pinMode(com_hear, INPUT); Serial.begin(9600);}vo...
2018-04-13 15:31:57
3001
1
原创 1556: 墓地秘密 (最短路+状压dp)
#include#include#include#define p(x,y) (x-1)*4+y+1using 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*
2014-11-15 14:48:22
1116
原创 1806: [Ioi2007]Miners 矿工配餐 (dp+滚动数组)
#include#include#includeusing namespace std;char ch[100010];int n,ans,f[5][4][4][4][4];int g(char c){ if(c=='M')return 1; if(c=='F')return 2; return 3;}int c(int x,int y,int z){ int r=1;
2014-11-14 22:44:16
675
原创 2599: [IOI2011]Race (点分治)
#include#include#define inf 1000000000using 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+c
2014-11-14 20:37:00
709
原创 2734: [HNOI2012]集合选数 (状压dp)
#include#include#include#define mod 1000000001using 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-'0';c
2014-11-14 14:58:13
566
原创 1086: [SCOI2005]王室联邦 (dfs+贪心)
#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-'0';ch=getchar();} return x*f;}str
2014-11-14 13:23:39
1055
原创 1193: [HNOI2006]马步距离 (贪心+搜索)
#include#include#include#include#includeusing namespace std;const int dx[8]={-2,-1,1,2,2,1,-1,-2},dy[8]={1,2,2,1,-1,-2,-2,-1};int sx,sy,ex,ey,dex,dey,s[200][200],ans=0;struct data{ int x,y;}
2014-11-14 11:14:48
683
原创 3631: [JLOI2014]松鼠的新家 (树形DP,树链剖分套线段树)
#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();} return x*f
2014-11-13 12:43:11
745
原创 3192: [JLOI2013]删除物品 (树状数组)
#include#include#includeusing namespace std;const int N=100005;int n,n1,n2,now,t[N];pair a[N];long long ans;inline int read(){ int x=0,f=1;char ch=getchar(); while(ch'9'){if(ch=='-')f=-1;ch=
2014-11-11 21:13:58
392
原创 2768: [JLOI2010]冠军调查 (最大流)
#include#include#include#define inf 0x7fffffffusing namespace std;struct data{ int to,next,v;}e[100001];int n,m,ans,cnt=1,head[305],h[305],q[305];void insert(int u,int v,int w){ e[++cn
2014-11-11 15:37:08
871
原创 2789: [Poi2012]Letters (树状数组求逆序对数)
#include#include#includeusing namespace std;char a[1000010],b[1000010];queue q[30];int n,v[1000010],t[1000010];long long ans;int query(int x){ int res=0; for(int i=x;i;i-=i&(-i)) res+=t[i]
2014-11-11 15:29:00
1130
原创 1098: [POI2007]办公楼biu (bfs+链表)
#include#include#include#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<=
2014-11-11 15:00:44
534
原创 2783: [JLOI2012]树 (dfs+平衡树)
#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();} r
2014-11-11 10:40:11
509
原创 1146: [CTSC2008]网络管理Network (线段树套平衡树+二分+树链剖分)
O(nlogn^4)#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-11-11 10:00:28
718
原创 1680: [Usaco2005 Mar]Yogurt factory (贪心)
#include#includeusing namespace std;int n,s,la;long long ans;int main(){ scanf("%d%d",&n,&s); for(int i=1;i<=n;i++){ int k,a;scanf("%d%d",&k,&a); if(la)k=min(k,la+s); ans+=k*a; la=k; }
2014-11-10 23:08:15
1108
原创 3721: PA2014 Final Bazarek (贪心)
#include#include#includeusing namespace std;const int N=1000010,inf=1000000000;int n,m,v[N],mx1[N],mx2[N],mn1[N],mn2[N];long long sum[N];int main(){ mn1[0]=mn2[0]=inf; scanf("%d",&n); for(in
2014-11-10 23:07:44
362
原创 2818: Gcd (欧拉函数)
#include#includeusing namespace std;const int N=10000011;int n,tot,pri[N],phi[N];long long ans,f[N];bool mark[N];void getphi(){ phi[1]=1; for(int i=2;i<=n;i++){ if(!mark[i])pri[++tot]=i,phi
2014-11-10 13:02:13
708
原创 Vijos P1780 开车旅行 (倍增+Treap)
#include#include#include#include#include#include#define inf 1000000001using namespace std;int n,m,NOW,a[200010],x0,Si[100001],Xi[100001],sz,rt,tmp,tmp2,da[200010][18],db[200010][18],to[200010]
2014-11-06 11:40:16
720
原创 Vijos P1757 逆序对 (动态规划)
#include #include #include using namespace std;int T,n,k,f[1010][1010];int main() { scanf("%d",&T); for(int i=1; i<=1000; i++)f[i][0]=1; for(int i=2; i<=1000; i++) for(int j=1
2014-11-05 20:47:47
583
原创 3436: 小K的农场 (差分约束)
#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')
2014-11-02 12:10:42
294
原创 3431: [Usaco2014 Jan]Bessie Slows Down (模拟)
#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')
2014-11-02 11:39:36
24699
原创 3404: [Usaco2009 Open]Cow Digit Game又见数字游戏 (博弈论)
#include#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'&
2014-11-02 11:05:04
496
原创 3402: [Usaco2009 Open]Hide and Seek 捉迷藏 (dijkstra+heap)
#include#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'&
2014-11-02 10:45:43
321
原创 1715: [Usaco2006 Dec]Wormholes 虫洞 (SPFA判负环)
#include#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'&
2014-11-02 09:48:11
261
原创 2711: [Violet 2]After 17 (动态规划+点积)
sigma(xi*xj+yi*yj)=[(x1+x2+...+xn)^2-(x1^2+x2^2+...xn^2)+(y1+y2+...+yn)^2-(y1^2+y2^2+...+yn^2)]/2#include#include#include#define ll long longusing namespace std;int n,X[201],Y[201];bool f[2][800
2014-11-01 23:02:09
356
原创 Vijos P1002 过河 (动态规划)
#include#include#include#includeusing namespace std;int f[20],a[200],n,s,t,m,p=1,ans=1000000000,now,tot;int main() { scanf("%d%d%d%d",&n,&s,&t,&m); for(int i=1; i<=m; i++) scanf(
2014-11-01 19:54:16
282
原创 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
280
原创 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
266
原创 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
371
原创 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
240
原创 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
194
原创 【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
383
原创 【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
267
原创 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
236
原创 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
281
原创 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
301
原创 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
526
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人