摘要: 第一个图论题,拓扑排序;挺容易的,基本上就是一个裸地拓扑排序;代码: 1 #include 2 #include 3 using namespace std; 4 int a[505][505],ans[505],cnt[505],n,m,x,y; 5 6 void top_sort() 7 { 8 for(int i=1; i<=n; i++) 9 for(int j=1; j<=n; j++)10 if(a[i][j]==1)11 cnt[j]++;12 for(int i=1; i<=n; i++)... 阅读全文
posted @ 2013-08-31 17:32 Yours1103 阅读(185) 评论(0) 推荐(0) 编辑
摘要: 昨天想了一下D题,有点思路不过感觉很麻烦,就懒得去敲了;今天上午也想了一下,还是没有结果,看了一下官方题解,证明得很精彩;这道题目其实就是一道裸地最大上升子序列的题;看到这里,直接怒码···· 1 #include 2 #include 3 using namespace std; 4 int a[100009]; 5 int main() 6 { 7 int n,k,x,cnt=0; 8 scanf("%d",&n); 9 for(int i=0;i<n;i++)10 {11 scanf("%d", 阅读全文
posted @ 2013-08-31 15:42 Yours1103 阅读(152) 评论(0) 推荐(0) 编辑
摘要: C题很容易看懂题目,不过两个循环肯定会TLE,所以得用点小聪明;首先排好序,因为是全排列,乱序和顺序的结果是一样的;然后呢····如果是数列 1 2 3 4 5元素1 被 2 3 4 5每个减了2次,它自己减0一次;相抵后为-7;元素2 被 3 5 4 每个减了2次,它减1两次,减0一次;相抵后为 -3;元素3 相抵后为1;可以发现他们的数量相差4;这样就好办了,一个循环就搞定了;代码: 1 #include 2 #include 3 #include 4 using namespace std; 5 int a[100009]; 6 long long 阅读全文
posted @ 2013-08-31 15:37 Yours1103 阅读(170) 评论(0) 推荐(1) 编辑
摘要: B题是一个计算几何的题,虽然以前看过计算几何的ppt,但一直都没有写过;昨晚比赛的时候本来想写的,但是怕不熟练浪费时间,太可惜了!其实没必要选出一个最大的矩形;以矩形的一条对角线为轴,向上或者向下找到最大的三角形的面积就行了,可以看看官方的题解,讲的挺不错的!代码: 1 #include 2 #define eps 0.00000001 3 using namespace std; 4 int a[305][2]; 5 double ccw(int x,int y,int z) 6 { 7 return ((double)(a[y][0]-a[x][0])*(a[z][1]-a[x][... 阅读全文
posted @ 2013-08-31 15:32 Yours1103 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 最水的题,可惜当时赶时间没有注意数据范围;暴力超时了!其实应该用x,y的最大公约数来判断;代码: 1 #include 2 using namespace std; 3 int gcd(int a,int b) 4 { 5 return b==0?a:gcd(b,a%b); 6 } 7 int main() 8 { 9 int x,y,a,b;10 cin>>x>>y>>a>>b;11 if(x<y)12 {13 x=x^y;14 y=x^y;15 x=x^y;16 }17 int k=x/... 阅读全文
posted @ 2013-08-31 15:28 Yours1103 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 看了codeforces上的大神写的题解之后,才知道这道题水的根本!不过相对前面两题来说,这道题的思维要难一点;不过想到了水的根本,这题也真心不难;方法嘛,就像剥洋葱一样,从外面往里面剥;所以呢,dfs,每次往左或者往右找到乱序的那个元素,反转一下;这样就行了,而且题目说了保证能够在三次内搞定;证明我也不会,意思应该就是这样了! 1 #include 2 #include 3 #include 4 #define maxn 1009 5 using namespace std; 6 int a[maxn],n; 7 vectorl,r; 8 bool found=0; 9 int checkl 阅读全文
posted @ 2013-08-27 21:10 Yours1103 阅读(168) 评论(0) 推荐(0) 编辑
摘要: 哎....这次的比赛被安叔骂的好惨!不行呢,要虐回来;这道搜索,老是写错,蛋疼啊!果然是基础没打好! 1 #include 2 using namespace std; 3 int ans[1009],m; 4 bool h[11],flag=true; 5 6 void dfs(int n,int ch,int x) 7 { 8 if(n>m) 9 {10 flag=false;11 printf("YES\n");12 for(int i=0; i<n; ++i)13 printf(" %d",ans... 阅读全文
posted @ 2013-08-27 11:15 Yours1103 阅读(243) 评论(0) 推荐(0) 编辑
摘要: 这题也是一个线段树的水题;不过开始题目没看明白,害得我敲了一个好复杂的程序。蛋疼啊。。。。最后十几分钟的时候突然领悟到了题意,但是还是漏掉一个细节,老是过不去。。。以后比赛的时候不喝啤酒了,再也不喝了。。。。贴上代码: 1 #include 2 #include 3 #define maxn 262200 4 using namespace std; 5 6 struct tree 7 { 8 int num; 9 int l,r;10 tree *left,*right;11 } tr[maxn];12 int nodecount=0,a;13 14 void up... 阅读全文
posted @ 2013-08-27 09:46 Yours1103 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 也是水题一个,不过稍微要细心点。。。。贴代码: 1 #include 2 using namespace std; 3 long long n,m; 4 long long ans=0; 5 int main() 6 { 7 long long s=0,t; 8 cin>>n>>m; 9 cin>>s;10 ans=s-1;11 for(int i=1;i>t;14 if(t<s)15 ans+=(n-s+t);16 else ans+=(t-s);17 s=t;18 }19... 阅读全文
posted @ 2013-08-27 09:42 Yours1103 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 水题一个;直接贴代码: 1 #include 2 #include 3 #include 4 using namespace std; 5 char s[110]; 6 int num[100]; 7 int main() 8 { 9 int cnt=0;10 scanf("%s",s);11 for(int i=0;i<strlen(s);i++)12 {13 if(s[i]!='+')14 num[cnt++]=s[i]-'0';15 }16 if(cnt==0) {printf("\n");return 0;. 阅读全文
posted @ 2013-08-27 09:40 Yours1103 阅读(134) 评论(0) 推荐(0) 编辑