锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
鑰岀洿鎺ヤ箻鎵?32ms銆?br>鐩稿樊涔熷お澶т簡鍚с?br>浜庢槸灝卞啓浜嗕竴孌典唬鐮佹潵嫻嬭瘯pow鐨勬ц兘
棣栧厛浜х敓10000涓殢鏈烘暣鏁幫紝鐒跺悗閲嶅1000嬈℃眰鏁存暟鐨勫鉤鏂?/p>
#include <iostream>
#include <cmath>
#include <ctime>
using Namespace stdnamespace std;
const int MAX = 10000;
int a[MAX];
int main()
{
int i, j, n = MAX;
int rep = 1000; //閲嶅嬈℃暟
clock_t beg, end;
for(i = 0; i < n; i++)
a[i] = rand() % 20000 - 10000; //-10000 <= a[i]< 10000
cout<<"test a[i]*a[i]"<<endl;
beg = clock();
for(j = 0; j < rep; j++)
for(i = 0; i < n; i++)
a[i] * a[i];
end = clock();
cout<<"time: "<<end - beg<<"ms"<<endl;
cout<<"test pow(a[i], 2.0)"<<endl;
beg = clock();
for(j = 0; j < rep; j++)
for(i = 0; i < n; i++)
pow(a[i], 2.0);
end = clock();
cout<<"time: "<<end - beg<<"ms"<<endl;
return 0;
}
涓嬮潰鏄祴璇曠粨鏋滐細
test a[i]*a[i]
time: 31ms
test pow(a[i], 2.0)
time: 2828ms
鎵浠ヤ笅嬈¢亣鍒扮被浼兼儏鍐典笉鍐嶇敤pow鍑芥暟浜?#8230;…
]]>const int VMAX = 1010;
typedef struct Graph
{
int vex;
Graph* next;
}Graph;
Graph ArcGraph[VMAX];
void insert(int u, int v)
{
Graph* t = new Graph;
Graph* p = ArcGraph[u].next;
t->vex = v;
t->next = p;
ArcGraph[u].next = t;
}
瀹屾垚瀹屾暣鐨勭▼搴忔彁浜や笂鍘伙紝寰楀埌緇撴灉
Memory:25796K Time:375MS
Language:C++ Result:Accepted
鍐嶅姣斿埆浜虹殑紼嬪簭
Memory:296K Time:109MS
鏃犺鏄椂闂磋繕鏄┖闂撮兘鐩稿樊寰堝ぇ銆?br>浜庢槸灝辮冭檻鎬庝箞浼樺寲鑷繁鐨勭▼搴忋?br>絎竴涓棶棰橈細瑙勬ā鍙湁1000錛屼負浠涔堜細鐢ㄩ偅涔堝鍐呭瓨鍛紵
浠旂粏涓鎯蟲暟鎹槸澶歝ase鐨勶紝姣忔鎻掑叆鏂拌妭鐐規椂閮借鍔ㄦ佸垱寤轟竴涓妭鐐廣?br>涓鏉ュ姩鎬佸垱寤鴻楁椂闂達紝浜屾潵姣忎釜case緇撴潫鐨勯偦鎺ヨ〃涓殑鑺傜偣娌℃湁閲婃斁錛屾晠鑰楄垂澶ч噺鍐呭瓨銆?br>鐒跺悗灝辨兂鍒頒簡涓嬮潰鐨勭畻娉曪紝棣栧厛鍒濆鍖栦竴鍧楀唴瀛楪raph use[100*VMAX];榪欐牱姣忔闇瑕佹柊鑺傜偣鏃訛紝
灝變粠use涓幏鍙栥傚鏋渦se浣跨敤瀹屾瘯灝卞啀鍔ㄦ佸垱寤恒?br>
渚濇綆楁硶浼樺寲鍚庯紝寰楀埌鐨勭粨鏋滄瘮杈冩弧鎰?br>Memory:1000K Time:218MS
Language:C++ Result:Acceptedconst int VMAX = 1010;
typedef struct Graph
{
int vex;
Graph* next;
}Graph;
Graph ArcGraph[VMAX];
Graph use[100*VMAX];
int size = 0;
void insert(int u, int v)
{
Graph* t;
if(size < 100*VMAX)
{
t = &use[size];
size++;
}
else t = new Graph;
Graph* p = ArcGraph[u].next;
t->vex = v;
t->next = p;
ArcGraph[u].next = t;
}
]]>#include<iostream>
using namespace std;
const int MAXV = 10000; //绱犳暟琛ㄨ寖鍥?br>
bool flag[MAXV+1]; //鏍囧織涓涓暟鏄惁涓虹礌鏁?br>
int prime[MAXV+1]; //绱犳暟琛?涓嬫爣浠?寮濮?br>
int size; //绱犳暟涓暟
void genPrime(int max)
{
memset(flag, true, sizeof(flag));
for(int i = 2; i <= max / 2; i++)
{
if(flag[i])
{
for(int j = i << 1 ; j <= max; j += i)
{
flag[j] = false;
}
}
}
for(int i = 2 ; i <= max; i++)
{
if(flag[i])
{
prime[size++] = i;
}
}
}
int main()
{
genPrime(MAXV);
return 0;
}
]]>#include<iostream>
#include<string>
using Namespace stdnamespace std;
const int MAXN = 9973; //鍝堝笇琛ㄩ暱搴?br>
const int len = 30; //瀛楃涓茬殑鏈澶ч暱搴?br>
int Htable[MAX];
char ch[MAX][len]; //瀛樺偍鍏抽敭瀛楃殑瀛楃涓?br>
unsigned long Hash(char * key)
{
unsigned long h = 0;
while(*key)
{
h = (h << 4) + *key++;
unsigned long g = h & 0xf0000000L;
if(g)
h ^= g >> 24;
h &= ~g;
}
return h % MAX;
}
int search(char * key)
{
unsigned long i = Hash(key);
while(Htable[i])
{
if(strcmp(ch[Htable[i]], key) == 0)
return i;
i = (i + 1) % MAX;
}
return -1;
}
int insert(char * key, int j) //j涓哄叧閿瓧鍦╟h涓殑浣嶇疆錛屽嵆绱㈠紩
{
unsigned long i = Hash(key);
while(Htable[i])
i = (i + 1) % MAX;
Htable[i] = j;
return i;
}
]]>
]]>
]]>
]]>
#include<cstdio>
int main()
{
int num = 10;
char str[100];
itoa(num, str, 2);
printf("%s\n", str);
return 0;
}itoa()鍑芥暟鏈?涓弬鏁幫細絎竴涓弬鏁版槸瑕佽漿鎹㈢殑鏁板瓧錛岀浜屼釜鍙傛暟鏄洰鏍囧瓧絎︿覆錛岀涓変釜鍙傛暟鏄漿縐繪暟瀛楁椂鎵鐢?鐨勫熀鏁般傚湪涓婁緥涓紝杞崲鍩烘暟涓?0銆?0錛氬崄榪涘埗錛?錛氫簩榪涘埗鈥︹?br />浜庢槸鎯沖埌浜嗕竴涓崄榪涘埗杞簩榪涘埗鐨勬柟娉曪細 #include<cstdlib>
#include<cstdio>
int main()
{
int num = 10;
char str[100];
int n = atoi(itoa(num, str, 2));
printf("%d\n",n);
return 0;
}
鍏堟妸num杞崲涓轟簩榪涘埗鐨勫瓧絎︿覆錛屽啀鎶婅瀛楃涓茶漿鎹負鏁存暟銆?/pre>
]]>
#include<cstdio>
const int MAX = 10000;
int a[MAX],b[MAX];
int change;
void merge(int p, int q, int r)
{
int i, j = 0;
int begA = p, endA = q, begB = q+1, endB = r;
while(begA <= endA && begB <= endB)
{
if(a[begA] <= a[begB])
b[j++] = a[begA++];
else
{
b[j++] = a[begB++];
change += q - begA + 1;
}
}
while(begA <= endA)
b[j++] = a[begA++];
while(begB <= endB)
b[j++] = a[begB++];
for(i = 0; i < j; i++)
a[p+i] = b[i];
}
void mergeSort(int first, int last)
{
if(first < last)
{
int mid = (first + last) / 2;
mergeSort(first, mid);
mergeSort(mid+1, last);
merge(first, mid, last);
}
}
int main()
{
return 0;
}
]]>#include<cstdio>
const int MAX = 10000;
const int INF = 1000000;
int d[MAX];
int c[MAX][MAX];
bool flag[MAX];
//int path[MAX];
int Dijkstra(int beg, int n)
{
int i, j, u, tmp;
for(i = 1; i <= n; i++)
{
d[i] = c[beg][i];
flag[i] = false;
/*if(d[i] == INF)
path[i] = 0;
else
path[i] = beg;*/
}
d[beg] = 0; flag[beg] = true;
for(i = 1; i <= n; i++)
{
tmp = INF; u = beg;
for(j = 1; j <=n; j++)
{
if(!flag[j] && d[j] < tmp)
{
u = j;
tmp = d[j];
}
}
flag[u] = true;
for(j = 1; j <= n; j++)
{
if(!flag[j] && c[u][j] < INF)
{
if(d[u] + c[u][j] < d[j])
d[j] = d[u] + c[u][j];
//path[j] = u;
}
}
}
return 0;
}
int main()
{
return 0;
}
]]>#include<cstdio>
const int MAX=10000;
const int INF=1000000;
int d[MAX][MAX];
int floyd (int n)
{
for(int k =1 ; k <= n; k++)
{
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
if(d[i][k] + d[k][j] < d[i][j])
d[i][j] = d[i][k] + d[k][j];
}
}
}
聽聽聽聽聽聽聽聽return 0;
}
int main()
{
return 0;
}
floyd鍚庯紝濡傛灉d[i][j]>=INF錛屽垯鐐筰鍒扮偣j娌℃湁璺?br />else鐐筰鍒扮偣j鐨勬渶鐭礬寰勯暱搴︿負d[i][j]銆?br />
]]>
bool prime(int a) { for(int i=2;i<=sqrt(a);i++) { if(a%i==0) return false; } return true; }
#ifndef UFSET_H #define UFSET_H class UFset { public: UFset(int); void Union(int ,int); int Find(int); int & operator [] (int i){return parent[i];} int size(){return length;} private: int length;//闆嗗悎鐨勪釜鏁? int * parent; }; UFset::UFset(int len) { length = len; parent = new int [length + 1]; for(int k = 1; k <= length; k++) parent[k] = -1; } int UFset::Find(int x) { int i; for(i = x; parent[i] >= 0; i = parent[i]);//鎼滅儲鏍硅妭鐐? while(i!=x)//璺緞鍘嬬緝 { int tmp = parent[x]; parent[x] = i; x = tmp; } return i; } void UFset::Union(int x,int y)//鍚堝茍 { int pX = Find(x); int pY = Find(y); if(pX != pY) { int tmp = parent[pX] + parent[pY]; if(parent[pX] > parent[pY]) { parent[pX] = pY; parent[pY] = tmp; } else { parent[pY] = pX; parent[pX] = tmp; } length--; } } #endif
The Triangle
Time Limit:1000MS聽 Memory Limit:10000K
Total Submit:3415 Accepted:1988
Description
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5
(Figure 1)
Figure 1 shows a number triangle. Write a program that calculates the highest sum of numbers passed on a route that starts at the top and ends somewhere on the base. Each step can go either diagonally down to the left or diagonally down to the right.
Input
Your program is to read from standard input. The first line contains one integer N: the number of rows in the triangle. The following N lines describe the data of the triangle. The number of rows in the triangle is > 1 but <= 100. The numbers in the triangle, all integers, are between 0 and 99.
Output
Your program is to write to standard output. The highest sum is written as an integer.
Sample Input
5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5
Sample Output
30
鍒嗘瀽錛?br />棰樻剰綆鍖栦負錛?br />浠庣涓琛屽紑濮嬭蛋鍒版渶鍚庝竴琛岋紝姣忔鍙互鍚戜笅璧版垨鍙充笅璧般?br />鎵姹傚嵆涓轟粠絎竴琛岃蛋鍒版渶鍚庝竴琛岀粡榪囩殑鏁版誨拰鐨勬渶澶у箋?br />浠[][]瀛樺偍input銆?br />5
7
3 8
8 1 0
2 7 4 4
|聽聽聽聽聽\ |聽 \
4 5 2 6 5
濡備笂鍥撅紝浠涓鴻錛宩涓哄垪,
d[i][j]涓轟粠絎竴琛岃蛋鍒扮i琛岀j鍒楃殑鏈澶у箋?br />瀵逛簬(i,j)榪欎釜鐐癸紝瀹冨彲浠ヤ粠涓嶅悓鏂瑰悜璧版潵錛屽鍥? | '浠h〃浠庝笂鏂硅蛋鏉ワ紝' \ '浠h〃浠庡乏涓婃柟璧版潵銆?br />
鍒欏姩鎬佽鍒欐柟紼嬩負錛?br />聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 聽{聽聽聽聽聽d[i-1][1]+p[i][1]聽聽聽(j=1)
d[i][j]=Max{聽聽聽聽 Max( d[i-1][j-1] , d[i-1][j] ) + p[i][j]聽聽聽(1<j<i)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {聽聽聽聽 d[i-1][i-1]+p[i][i]聽聽聽(j=i)
緇撴灉涓篗ax(d[n][j]) , (1<=j<=n)
浠g爜濡備笅錛?pre>#include<cstdio>
int p[100][100];
int d[100][100];
int Max(int a,int b)
{return a>b?a:b;}
int main()
{
int i,n;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
int j;
for(j=1;j<=i;j++)
scanf("%d",p[i]+j);
}
d[1][1]=p[1][1];
for(i=2;i<=n;i++)
{
int j;
d[i][1]=d[i-1][1]+p[i][1];
for(j=2;j<=i;j++)
d[i][j]=Max(d[i-1][j-1],d[i-1][j])+p[i][j];
d[i][i]=d[i-1][i-1]+p[i][i];
}
int max=0;
for(i=1;i<=n;i++)
{
if(d[n][i]>max)
max=d[n][i];
}
printf("%d\n",max);
return 0;
}
LETTERS
Time Limit:1000MS聽 Memory Limit:10000K
Total Submit:694 Accepted:334
Description
A single-player game is played on a rectangular board divided in R rows and C columns. There is a single uppercase
letter (A-Z) written in every position in the board.
Before the begging of the game there is a figure in the upper-left corner of the board (first row, first column). In every move, a player can move the figure to the one of the adjacent positions (up, down,left or right). Only constraint is that
a figure cannot visit a position marked with the same letter twice.
The goal of the game is to play as many moves as possible.
Write a program that will calculate the maximal number of positions in the board the figure can visit in a single game.
Input
The first line of the input contains two integers R and C, separated by a single blank character, 1 <= R, S <= 20.
The following R lines contain S characters each. Each line represents one row in the board.
Output
The first and only line of the output should contain the maximal number of position in the board the figure can visit.
Sample Input3 6
HFDFFB
AJHGDH
DGAGEH
Sample Output6
鎴戠殑紼嬪簭錛?br />#include<cstdio> #include<stack> using namespace std; struct node { int row; int col; int dire; }; char p[30][30]; char flag[30]; int incr[4][2]={{0,1},{1,0},{0,-1},{-1,0}}; int main() { int i,row,col; scanf("%d%d",&row,&col); getchar(); char ch[30]; for(i=1;i<=row;i++) { gets(ch); int j; for(j=1;j<=col;j++) p[i][j]=ch[j-1]; } //鍒濆鍖栵紝澶栧姞涓灞? for(i=0;i<=col+1;i++) { p[0][i]='0'; p[row+1][i]='0'; } for(i=0;i<=row+1;i++) { p[i][0]='0'; p[i][col+1]='0'; } int Maxmove=0;//鏈澶ф鏁? stack<node>path;
聽聽聽聽聽聽聽聽//鏍堝垵濮嬪寲 int r=1,c=1,dire=0,f=0,move=1; node in; in.row=r; in.col=c; in.dire=dire; path.push(in); flag[f++]=p[r][c]; while(!path.empty()) { if(dire<4) { int r2=r+incr[dire][0]; int c2=c+incr[dire][1]; bool b=true; for(int k=0;k<f;k++)//鎼滅儲鏄惁宸茶闂垨璺笉閫? { if(flag[k]==p[r2][c2] || p[r2][c2]=='0') { dire++; b=false; break; } } if(b)//璺? { node in; in.row=r2; in.col=c2; in.dire=dire; path.push(in);//榪涙爤 move++; flag[f++]=p[r2][c2];//鏍囧織宸茶闂? r=r2; c=c2; dire=0; } } else//鎵懼埌涓涓В { if(move>Maxmove) Maxmove=move; move--; dire=path.top().dire+1; //鍥炴函錛屽幓闄よ闂爣蹇? path.pop(); flag[--f]='\0'; if(!path.empty()) { r=path.top().row; c=path.top().col; } } } printf("%d\n",Maxmove); return 0; }
Gopher and hawks
Time Limit:1000MS聽 Memory Limit:65536K
Total Submit:900 Accepted:328
Description
A gopher sits in a hole located at (xs, ys) and wants to get to a hole located at (xt, yt). The gopher can run at a constant speed of v m/sec. However, if the gopher is outside of a hole for more than a m minutes he will become a supper to hawks flying over the holes. Can the gopher make it?
Input
The first line of input contains two positive integer numbers: v -- gopher's speed in meters per second and m -- the time after which the gopher becomes prey to hawks if he stays outside a hole. The second line of input contains two floating point numbers: the (xs,ys) coordinates of the gopher starting hole. The third line contains the (xt, yt) coordinates of the target hole. Each Subsequent line of input contains two floating point numbers: the (x,y) coordinates of a gopher hole. All distances are in metres, to the nearest mm.
Output
If the gopher can make it to the target hole, the output line should read "Yes, visiting n other holes.", where n is the minimal number of intermediate holes the gopher has to visit. If the gopher cannot make it the output line should read "No." There are not more than 1000 gopher holes and all coordinates are between -10000 and +10000.
Sample Input
3 1
0.000 0.000
500.000 0.000
179.000 0.000
358.000 0.000
Sample Output
Yes, visiting 2 other holes.
Hint
Sample input 2
5 1
0.000 0.000
0.000 550.000
179.000 0.000
0.000 301.000
Output for sample input 2
No.
鎴戠殑紼嬪簭錛?br />#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
struct node
{
int point;
int step;
};
double x[1100],y[1100];
bool flag[1100]={false};
int main()
{
int i,v,t;
scanf("%d%d",&v,&t);
t*=60;
double beginX,beginY,endX,endY;
scanf("%lf%lf%lf%lf",&beginX,&beginY,&endX,&endY);
int n=1;
while(scanf("%lf%lf",x+n,y+n)!=EOF)
n++;
x[0]=beginX;
y[0]=beginY;
x[n]=endX;
y[n]=endY;
node n1;//闃熷垪鍒濆鍖?
n1.point=0;
n1.step=0;
queue<node> que;
que.push(n1);
int steps=0;
while(true)
{
if(que.empty())
break;
node tmp=que.front();
que.pop();//鍑洪槦鍒?
for(i=1;i<=n;i++)
{
if(!flag[i])//鏍囧織鏄惁榪涜繃闃熷垪
{
double time=sqrt(pow(x[i]-x[tmp.point],2.0)+pow(y[i]-y[tmp.point],2.0))/v;
if(time<t)
{
if(i==n)
{
steps=tmp.step;
goto next;
}
else
{
node in;
in.point=i;
in.step=tmp.step+1;
que.push(in);//榪涢槦鍒?
flag[i]=true;
}
}
}
}
}
next:
if(steps!=0)
printf("Yes, visiting %d other holes.\n",steps);
else
printf("No.\n");
return 0;
}
My Status
Problem
|
status
|
time
|
A
|
Yes
|
39
|
B
|
Yes
|
77
|
G
|
No-Time-limit Exceeded
|
96
|
G
|
Yes
|
113
|
C
|
Yes
|
211
|
E
|
No-Time-limit Exceeded
|
265
|
Solved 4聽聽聽聽Time 460
棰樼洰璇存槑瑕佽緭鍏ョ殑瀛楃涓查暱搴︽渶澶氫負8銆?/font>
鍥犳鎴戝氨鍙敵璇蜂簡8涓瓧絎︺?/font>
緇撴灉褰撶劧灝辨槸閿欎簡銆?/font>
鍏跺疄瀛楃鏁扮粍闇瑕佷竴涓瓨鍌ㄥ崟鍏冩潵淇濆瓨緇撴潫絎︹淺0鈥濓紝
鐢ㄦ潵璇存槑涓涓瓧絎︿覆緇撴潫浜嗐?/font>
鍥犳瑕佺敵璇鋒瘮瀛楃涓插涓涓瓨鍌ㄥ崟鍏冪殑闀垮害銆?/font>
璁頒綇浜嗭紒錛?/font>
浠庢涓嶈兘鐘悓鏍烽敊璇紒