摘要: 如题:广度优先搜索
#include < stdio.h >int hash[105][105];typedef struct{ int l, c;}type;type q[50000];int head, tail;int mo... 阅读全文
摘要: 题目的意思是要我们去掉最多的边使图还是连通的,同了强连通分支的算法。如下:
#include <stdio.h>const int LEN = 5005;struct HEAD { int state; //搜索状态  ... 阅读全文
摘要: 堆优化的最短路径,其实可以用SPFA做的,效果会相当会
//堆优化的最短路径不知道什么原因的AC#include <stdio.h>const int MAX_N = 30005;const int MAX_M = 150005;const int MAX =&nb... 阅读全文
题目就是考察一个循环队列。
#include <stdio.h>
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int queue[105];
int len,head;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
void setq(int n)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
int i;
len = n;
head = 0;
for(i=0;i<len;i++)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
scanf("%d",&queue[i]);
}
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int max()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
int i,m = queue[head],p=(head+1)%len,m_i=head;
for(i=1;i<len;i++)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if(queue[p]>m)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
m = queue[p];
m_i = p;
}
p = (p+1)%len;
}
return m_i;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int outq()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
int a;
head = max();
a = head;
queue[head] = -1;
head = (head+1)%len;
return a;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int main()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
int i,count;
int T,N,M;
scanf("%d",&T);
for(i=0;i<T;i++)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
scanf("%d%d",&N,&M);
setq(N);
count = 1;
while(outq()!=M) count ++;
printf("%d\n",count);
}
return 0;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
题目的整体思想就是二份答案,将复杂度降低。
1 #include<stdio.h> 2 #include<math.h> 3 double ri[10005]; 4 int judge(double m,int pie_n,int friend_n,double *p) 5![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) { 6 int i,sum=0; 7 for(i=1;i<=pie_n;i++) 8![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) { 9 sum+=int((p[i]*acos(-1))/m); 10 } 11 if(sum>friend_n) 12 return 1; 13 else 14 return 0; 15 } 16 double abs(double ll) 17![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) { 18 if(ll<0) 19 return ll*(-1); 20 else 21 return ll; 22 } 23 int main() 24![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) { 25 int t,pie_n,friend_n,i; 26 scanf("%d",&t); 27 while(t--) 28![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) { 29 double mm=0; 30 scanf("%d%d",&pie_n,&friend_n); 31 for(i=1;i<=pie_n;i++) 32![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) { 33 scanf("%lf",&ri[i]); 34 ri[i]=ri[i]*ri[i]; 35 if(ri[i]>mm) 36 mm=ri[i]; 37 } 38 double min=0,max=mm*acos(-1),mid; 39 while(abs(max-min)>0.000005) 40![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) { 41 mid=(max+min)/2; 42 if(judge(mid,pie_n,friend_n,ri)) 43![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) { 44 min=mid; 45 } 46 else 47![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) { 48 max=mid; 49 } 50 } 51 printf("%.4lf\n",mid); 52 } 53 return 0; 54 } 55![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
年代太久,都有点忘记了!
#include "stdio.h"
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int judge(__int64 a,int n,__int64 b)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
int i;
__int64 sum=1;
for(i=0;i<n;i++)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
sum*=a;
if(sum>=b)break;
}
if(i>=n)return -1;
else return 1;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
__int64 power(__int64 a,int n)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
__int64 sum=1;
__int64 temp=a;
while(n!=0)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if(n&1)sum*=temp;
temp*=temp;
n>>=1;
}
return sum;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
__int64 min(__int64 a,__int64 b,int n,__int64 p)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
return (p-power(a,n)<power(b,n)-p)?a:b;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int main()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
int n;
__int64 b;
__int64 left,right,middle;
while(1)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
scanf("%I64d%d",&b,&n);
if(b==0&&n==0)break;
left=0;right=b;
while(left<=right)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
middle=(left+right)/2;
if(judge(middle,n,b)>0)right=middle-1;
else left=middle+1;
}
printf("%I64d\n",min(right,left,n,b));
}
return 0;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
代码如下:
|
|
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
---|
28 | 29 | 30 | 31 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|
公告
决定从线程开始!!
常用链接
留言簿(6)
随笔档案
搜索
最新评论
![](/images/xml.gif)
阅读排行榜
评论排行榜
|
|