随笔分类 -  杂题

摘要:思路:将每个关系当成一条有向边,查询时就判断之间存在路径。#include#include#include#include#include#include#define Maxn 210using namespace std;map g;map ver;int head[Maxn*2],vi[Maxn*2],e;struct Edge{ int u,v,next;}edge[Maxn*Maxn*2];void add(int u,int v){ edge[e].u=u,edge[e].v=v,edge[e].next=head[u],head[u]=e++;}bool dfs(in... 阅读全文
posted @ 2013-10-13 15:40 fangguo 阅读(252) 评论(0) 推荐(0)
摘要:思路:直接vector暴力#include#include#include#include#define Maxn 2000010using namespace std;vector g;char str[Maxn],ss[20];int main(){ int t,i,j,l,pos,ll,r; scanf("%d",&t); while(t--){ g.clear(); scanf("%s",str); l=strlen(str); for(i=0;i<l;i++) g.push_back(st... 阅读全文
posted @ 2013-10-12 17:28 fangguo 阅读(218) 评论(0) 推荐(0)
摘要:思路:先O(n)预处理出ri[i][j],le[i][j],分别表示第i个位置向右边移动出j个空格需要的步数,表示第i个位置向左边移动出j个空格需要的步数。然后枚举间隙处,二分判段最大间隔。#include#include#include#include#define Maxn 710#define inf 100000000using namespace std;int ri[Maxn][Maxn],le[Maxn][Maxn],n,m;char str[Maxn];bool OK(int pos,int x){ int i,j,cnt=inf; if(pos==1) { ... 阅读全文
posted @ 2013-10-06 15:05 fangguo 阅读(280) 评论(0) 推荐(1)
摘要:思路:见代码#include#include#include#include#define Maxn 110using namespace std;int a[Maxn][Maxn],b[Maxn][Maxn],n,k;bool equel(){ int i,j; for(i=1;i1) return false; return true;}bool bb(){ int i,j; for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ if(b[i][j]!=b[j][i]) r... 阅读全文
posted @ 2013-10-05 14:57 fangguo 阅读(230) 评论(0) 推荐(0)
摘要:思路:这题对于其他能退出所有值的情况比较好像,唯一不能确定的是XXOXXOXXOXX这个形式的序列,其中XX表示未知,O表示已知。我们令num[1]=0,那么num[4]=sum[3]-sum[2]+num[1];可以递推,num[i]=sum[i-1]-sum[i-2]+num[i-3],(i%3==1)。这样求出来的每个num值就是相对于num[1]的值。假使某个num[i]=(-num[i])。所以num[1]>=max(-num[i]).同理可以求出所有相对于num[2]的值。#include#include#include#include#include#include#inc 阅读全文
posted @ 2013-09-23 20:42 fangguo 阅读(329) 评论(0) 推荐(0)
摘要:思路:直接打表#include#include#include#includeusing namespace std;int num[10010]={0,1356,1967,2577,3188,3799,5156,13154,13762,14374,14985,16341,16953,17563,18174,18785,20142,20753,21364,21975,22587,23942,24554,25165,25775,26387,27744,28355,28966,29576,30187,31544,32155,32767,33375,33987,35344,35954,36566,3 阅读全文
posted @ 2013-09-05 16:14 fangguo 阅读(598) 评论(0) 推荐(0)
摘要:思路:枚举能是A,B,C在一条简单路径上的中点。 计算多少个几何能满足。在用总数减去#pragma comment(linker, "/STACK:16777216")#include#include#include#include#include#include#include#include#include#include#include#define Maxn 200010#define Maxm 300010#define LL __int64#define Abs(x) ((x)>0?(x):(-x))#define lson(x) (x son[Maxn] 阅读全文
posted @ 2013-08-23 15:36 fangguo 阅读(189) 评论(0) 推荐(0)
摘要:思路:主要就是模拟这些操作,用链表果断超时。改用堆栈模拟就过了#include#include#include#include#include#include#include#include#include#include#include#include#define Maxn 1000010#define Maxm 300010#define LL __int64#define Abs(x) ((x)>0?(x):(-x))#define lson(x) (x br,af;int main(){ int i,j,u,v,n,x; char str[3]; int brz,a... 阅读全文
posted @ 2013-08-23 15:31 fangguo 阅读(184) 评论(0) 推荐(0)
摘要:思路:用map将每个字符串与一个数字进行对应,然后暴力统计就好了#include#include#include#include#include#include#include#include#define Maxn 2010using namespace std;int fr[Maxn][Maxn],mul[Maxn][Maxn],Max[Maxn];char str[Maxn][20];map g;vector head[Maxn*2];vector ans[Maxn*2];int cmp(int a,int b){ return strcmp(str[a],str[b])<0;}i 阅读全文
posted @ 2013-08-22 19:02 fangguo 阅读(226) 评论(0) 推荐(0)
摘要:题意:每个用户对数据库的查询请求都会首先用该数据库的服务器序列的第一个去执行任务,若第一个坏了,就由第二个执行。最多只会坏一个服务器。要求是考虑最多坏一个的情况下,所有服务器中执行用户查询的数目最大值与最小值之差不能超过1。思路:对于n>=m的情况,很容易能解决掉,关键是n#include#include#include#includeusing namespace std;int ans[110][3],pre[110],vi[110],num[110],n,m;struct Que{ int val,c; int operator temp.c; }};int Ok(){... 阅读全文
posted @ 2013-08-14 15:03 fangguo 阅读(268) 评论(0) 推荐(0)