锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
2
3 Submit Time: 2012-02-18 01:33:04 Language: GNU C Result: Accepted
4 Pid: 3124 Time: 0.00 sec. Memory: 852 K. Code Length: 0.6 K.
5 # include <stdio.h>
6 # define cross(x1,y1,x2,y2) (x1)*(y2)-(x2)*(y1)
7 # define get_aera(x0,y0,x1,y1,x2,y2) (cross((x1)-(x0),(y1)-(y0),(x2)-(x0),(y2)-(y0)))
8 int main()
9 {
10 int n;
11 while(scanf("%d",&n)!=EOF&&n)
12 {
13 int i;
14
15 double x[3],y[3],aera=0;
16 scanf("%lf%lf",&x[2],&y[2]);
17 for(i=1;i<n;i++)
18 {
19 scanf("%lf%lf",&x[i%2],&y[i%2]);
20 if(i>1) aera+=get_aera(x[2],y[2],x[(i+1)%2],y[(i+1)%2],x[i%2],y[i%2]);
21 }
22 aera*=0.5;
23 if(aera<0) aera=-aera;
24 printf("%.0f\n",aera+1e-8);
25
26 }
27 return 0;
28 }
]]>
瑙f硶錛?br>鍏堢粰鍑轟竴涓畾鐞嗭細(xì)嫻蜂雞鍏紡
涓嬮潰灝辨槸鏋氫婦杈歸暱銆傞鍏堟灇涓炬渶闀胯竟c錛岀敱浜庝袱杈逛箣鍜屽ぇ浜庣涓夎竟錛宑鐨勯暱搴﹀繀欏誨皬浜庡懆闀跨殑涓鍗婏紝榪欐槸涓涓噸瑕佺殑鍓灊銆傚鏋滆繕瑕佸壀鏋濓紝鍙互鍏堜竴嬈P姹傚緱鐢辨湪媯嶇粍鍚堝彲浠ヨ揪鍒扮殑闀垮害銆?br>紜畾c浠ュ悗鍐嶆灇涓綼錛岀劧鍚庡啀嬈″彲浠ョ敤DP楠岃瘉鏈ㄦ鑳藉惁緇勫悎鎴恆銆乧鐨勯暱搴︺傝繖閲屽彲浠ュ啀涓嬈″壀鏋濓紝鏋氫婦c鐨勬椂鍊欏緩璁粠鍛ㄩ暱鐨勪竴鍗婂悜涓嬫灇涓撅紝鍘熷洜寰堢畝鍗曪紝灝介噺鏋勯犱竴涓緝浼樼殑鍚堟硶瑙o紝鏍規(guī)嵁?huà)狗潆u鍏紡(p-a)(p-b)(p-c)錛屽綋c紜畾鏃舵渶澶у肩殑浣嶇疆涔熸竻妤氫簡(jiǎn)錛坆鍜宑鐩哥瓑鐨勪綅緗紝濡傛灉鍦ㄦ渶浼樹(shù)綅緗紙涓婇檺錛屽彲鑳借揪涓嶅埌錛夐兘涓嶈兘姣旀渶浼樿В浼橈紝灝辯洿鎺ut錛夈傜劧鍚庝笅闈㈠氨娌′粈涔堥毦搴︿簡(jiǎn)銆?br>
浠g爜錛?br>
2 # include <cstring>
3 # include <cstdlib>
4 # include <cmath>
5 using namespace std;
6 # include <algorithm>
7 bool dp[2][855][855];
8 int plen[1605],pc=0;
9 int n,len[41];
10
11 int main()
12 {
13 int total=0;
14 scanf("%d",&n);
15 for(int i=0;i<n;i++)
16 {
17 scanf("%d",len+i);
18 total+=len[i];
19 }
20 sort(len,len+n);
21 bool tmp[1606];
22 memset(tmp,false,sizeof(tmp));
23 memset(dp[0],0,sizeof(dp[0]));
24 dp[0][0][0]=true;
25 for(int i=1;i<=n;i++)
26 {
27 memset(dp[i%2],false,sizeof(dp[i%2]));
28 for(int j=0;j<=total/2+40;j++)
29 for(int k=j;k<=total/2+40;k++)
30 if(j-len[i-1]>=0&&dp[(i-1)%2][min(j-len[i-1],k)][max(j-len[i-1],k)]||
31 k-len[i-1]>=0&&dp[(i-1)%2][min(j,k-len[i-1])][max(k-len[i-1],j)]||
32 dp[(i-1)%2][j][k])
33 dp[i%2][j][k]=true;
34 }
35
36 tmp[len[0]]=true;
37 for(int i=1;i<n;i++)
38 for(int j=0;j<=total;j++)
39 if(tmp[j]&&j+len[i]<=total)
40 tmp[j+len[i]]=true;
41 for(int i=0;i<=total;i++)
42 if(tmp[i])
43 plen[pc++]=i;
44 int best=-1;
45 for(int c=lower_bound(plen,plen+pc,total/2)-plen-1;c>=0;c--)
46 {
47 int a=(total-plen[c])/2,b=total-plen[c]-a;
48 if(best!=-1&&(total-2*plen[c])*(total-2*a)*(total-2*b)<best) continue;
49 for(a=0;plen[a]<total-plen[c];a++)
50 if(plen[c]>=plen[a]&&plen[c]>=total-plen[a]-plen[c]&&dp[n%2][plen[a]][plen[c]]&&(best==-1||best<(total-2*plen[c])*(total-2*plen[a])*(total-2*(total-plen[a]-plen[c]))))
51 best=(total-2*plen[c])*(total-2*plen[a])*(total-2*(total-plen[a]-plen[c]));
52 }
53 if(best==-1) printf("-1\n");
54 else
55 {
56 best=(int)(sqrt(best*(double)total)*25+1e-6);
57 printf("%d\n",best);
58 }
59 //system("pause");
60 return 0;
61
62 }
63
]]>
]]>

緇欏嚭涓猲琛岀殑涓夎錛屾瘡涓渾閲屽寘鍚竴涓瓧姣嶏紝闂摢浜涘瓧姣嶈兘澶熺粍鎴愮瓑杈逛笁瑙掑艦錛堟瘡涓瓧姣嶈嚦澶氬嚭鐜?嬈★級(jí)
瑙f硶錛?br>鎴戠敤浜?jiǎn)涓緢鎳掔殑鏂规硶锛尳帡姣忎釜鍦嗕腑蹇?jī)鐐圭殑鍧愭爣錛岀劧鍚庣湅涓夌偣璺濈鏄惁鐩哥瓑銆傚叧浜庢眰鍧愭爣鍏跺疄榪樻槸寰堢畝鍗曠殑- -鐢ㄥ悜閲忕殑鏂規(guī)硶銆?br>絎竴琛岀涓涓潗鏍囪涓猴紙0錛?錛夛紝璁劇疆鍏冨悜閲?-0.5,-0.5*sqrt(3))錛岀劧鍚庢瘡涓琛岀涓涓厓绱犲潗鏍囧氨鏄笂琛岀涓涓厓绱犲潗鏍?鍏冨悜閲忥紝姣忎竴琛岀i涓厓绱犲潗鏍囦負(fù)絎琲-1涓潗鏍?鍗曚綅鍚戦噺銆?br>
浠g爜錛?br>
2 // Name : pku1244.cpp
3 // Author : yzhw
4 // Version :
5 // Copyright : yzhw
6 // Description : Hello World in C++, Ansi-style
7 //============================================================================
8
9 #include <iostream>
10 #include <cstdio>
11 #include <cstring>
12 #include <cmath>
13 #include <algorithm>
14 #include <functional>
15 #include <vector>
16 using namespace std;
17 double x=-0.5,y=x*sqrt(3.0);
18 int n;
19 inline double dis(pair<double,double> a,pair<double,double> b)
20 {
21 return (a.first-b.first)*(a.first-b.first)+(a.second-b.second)*(a.second-b.second);
22 }
23 inline double equ(double a,double b)
24 {
25 return fabs(a-b)<1e-6;
26 }
27 int main() {
28 double data[20][20][2];
29 while(scanf("%d",&n)&&n)
30 {
31 char str[255];
32 vector<pair<double,double> > map[26];
33 scanf("%s",str);
34 char *p=str;
35 data[0][0][0]=0;
36 data[0][0][1]=0;
37 map[*(p++)-97].push_back(make_pair<double,double>(data[0][0][0],data[0][0][1]));
38 for(int i=1;i<n;i++)
39 {
40 data[i][0][0]=data[i-1][0][0]+x;
41 data[i][0][1]=data[i-1][0][1]+y;
42 map[*(p++)-97].push_back(make_pair<double,double>(data[i][0][0],data[i][0][1]));
43 for(int j=1;j<=i;j++)
44 {
45 data[i][j][0]=data[i][j-1][0]+1;
46 data[i][j][1]=data[i][j-1][1];
47 map[*(p++)-97].push_back(make_pair<double,double>(data[i][j][0],data[i][j][1]));
48 }
49 }
50 bool flag=false;
51 for(int i=0;i<26;i++)
52 if(map[i].size()==3)
53 {
54 if(equ(dis(map[i][0],map[i][1]),dis(map[i][0],map[i][2]))&&equ(dis(map[i][0],map[i][1]),dis(map[i][1],map[i][2])))
55 {
56 printf("%c",i+97);
57 flag=true;
58 }
59 }
60 if(flag) printf("\n");
61 else printf("LOOOOOOOOSER!\n");
62 }
63 return 0;
64
65 }
66
]]>
]]>
]]>
璁$畻綾諱技榪欐牱涓涓浘褰㈢殑闈㈢Н銆佽竟涓婄殑鏍肩偣鏁般佸唴閮ㄦ牸鐐規(guī)暟
瑙f硶錛?br>榪欓噷鐢ㄥ埌涓涓畾鐞嗭紝鍙玴ick瀹氱悊
闈㈢Н=杈逛笂鐐規(guī)暟/2-1+鍐呴儴鐐規(guī)暟
鐒跺悗姹傝竟涓婄殑鐐規(guī)暟鐩存帴鐢╣cd(dx,dy)灝卞彲浠ヤ簡(jiǎn)銆?br>緗戞牸鍥炬槸涓涓濂囩殑鍥撅紝閲岄潰鏈夊緢澶氳寮傜殑緇撹銆?br>
浠g爜錛?br>
# include <stdio.h>
2
# define cross(x1,y1,x2,y2) ((x1)*(y2)-(x2)*(y1))
3
int p[105][2];
4
int gcd(int n1,int n2)
5

{
6
if(n1<0) n1*=-1;
7
if(n2<0) n2*=-1;
8
while(n2)
9
{
10
int t=n1%n2;
11
n1=n2;
12
n2=t;
13
}
14
return n1;
15
}
16
int main()
17

{
18
//freopen("ans.txt","w",stdout);
19
int test,t;
20
scanf("%d",&test);
21
for(t=1;t<=test;t++)
22
{
23
int n,i;
24
int aera=0,edge=0;
25
scanf("%d",&n);
26
for(i=1;i<=n;i++)
27
{
28
scanf("%d%d",&p[i][0],&p[i][1]);
29
edge+=gcd(p[i][0],p[i][1]);
30
}
31
p[0][0]=p[0][1]=0;
32
for(i=1;i<n;i++)
33
p[i][0]+=p[i-1][0],p[i][1]+=p[i-1][1];
34
for(i=2;i<n;i++)
35
aera+=cross(p[i-1][0],p[i-1][1],p[i][0],p[i][1]);
36
printf("Scenario #%d:\n%d %d %.1f\n\n",t,(int)((aera+2-edge)*0.5+1e-6),edge,aera*0.5);
37
}
38
// system("pause");
39
return 0;
40
}
41
]]>
瑙f硶錛?br>棣栧厛鑳藉鍞竴紜畾鐨勬潯浠舵槸鐢卞墿涓嬬殑鏈ㄦ々紜畾鐨勫嚫鍖呯殑姣忔潯杈逛笂鑷沖皯鍖呭惈3涓湪妗╋紝榪欎釜鑷繁鐢誨浘姣斿垝涓嬪氨鐭ラ亾浜? -
鐒跺悗灝辨槸姹備竴涓嚫鍖呬簡(jiǎn)銆傚湪榪欑鍧愭爣閮芥槸鏁存暟鐨勬儏鍐典笅錛屽嚫鍖呮渶濂戒笉瑕佺敤atan2鍑芥暟錛岃屾槸鐢ㄥ弶縐潵姣旇緝銆傛垜鐗瑰湴鐢ㄧ函C鍐欎簡(jiǎn)涓紝鏈夎鐨勭闉嬪彲浠ユ嬁鍘誨綋妯℃澘
鏈変釜闃撮櫓鐨勫湴鏂癸紝灝辨槸嫻嬭瘯鏁版嵁鍙湁3涓偣錛岃屼笖3鐐逛竴綰褲傘傘備綘鎳傜殑
浠g爜
# include <stdio.h>
2
# include <stdlib.h>
3
# define N 1200
4
# define cross(x1,y1,x2,y2) ((x1)*(y2)-(x2)*(y1))
5
# define min(a,b) ((a)<(b)?(a):(b))
6
# define max(a,b) ((a)>(b)?(a):(b))
7
typedef struct
8

{
9
int x,y;
10
}point;
11
int n,c;
12
point data[N],ans[N],std;
13
int dis(point *pos)
14

{
15
return (pos->x-std.x)*(pos->x-std.x)+(pos->y-std.y)*(pos->y-std.y);
16
}
17
int isin(point *a,point *b,point *pos)
18

{
19
if(pos->x>max(a->x,b->x)||pos->x<min(a->x,b->x)||pos->y>max(a->y,b->y)||pos->y<min(a->y,b->y)) return 0;
20
else if(cross(pos->x-a->x,pos->y-a->y,b->x-a->x,b->y-a->y)!=0) return 0;
21
else return 1;
22
}
23
int cmp(const void *a,const void *b)
24

{
25
point *aa=(point *)a,*bb=(point *)b;
26
if(cross(bb->x-std.x,bb->y-std.y,aa->x-std.x,aa->y-std.y))
27
return cross(bb->x-std.x,bb->y-std.y,aa->x-std.x,aa->y-std.y);
28
else
29
return dis(aa)-dis(bb);
30
}
31
void sort()
32

{
33
int i;
34
int x=0xfffffff,y=0xfffffff;
35
for(i=0;i<n;i++)
36
if(data[i].y<y||data[i].y==y&&data[i].x<x)
37
y=data[i].y,x=data[i].x;
38
std.x=x;
39
std.y=y;
40
qsort(data,n,sizeof(point),cmp);
41
}
42
void build()
43

{
44
int i;
45
c=0;
46
sort();
47
for(i=0;i<n;i++)
48
{
49
while(c>=2&&cross(data[i].x-ans[c-1].x,data[i].y-ans[c-1].y,ans[c-1].x-ans[c-2].x,ans[c-1].y-ans[c-2].y)>=0) c--;
50
ans[c++]=data[i];
51
}
52
if(c>0) ans[c++]=ans[0];
53
}
54
int chk()
55

{
56
int i;
57
for(i=0;i<c-1;i++)
58
{
59
int count=0,j;
60
for(j=0;j<n;j++)
61
if(isin(&ans[i],&ans[i+1],&data[j]))
62
count++;
63
if(count<3) return 0;
64
}
65
return 1;
66
}
67
int main()
68

{
69
int test;
70
scanf("%d",&test);
71
while(test--)
72
{
73
int i;
74
scanf("%d",&n);
75
for(i=0;i<n;i++)
76
scanf("%d %d",&data[i].x,&data[i].y);
77
build();
78
if(c>3&&chk()) printf("YES\n");
79
else printf("NO\n");
80
}
81
return 0;
82
}
83
]]>
]]>
]]>
# include <iostream>
# include <cmath>
using namespace std;
# include <set>
struct cmp

{
bool operator()(const double a,const double b) const
{
return fabs(a-b)>1e-8&&a<b;
}
};
set<double,cmp> refer;
bool sp=0;
int data[201][2];
int main()

{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>data[i][0]>>data[i][1];
for(int j=0;j<i;j++)
if(data[j][0]==data[i][0])
sp=1;
else
refer.insert((data[j][1]-data[i][1])/(double)(data[j][0]-data[i][0]));
}
cout<<refer.size()+sp<<endl;
// system("pause");
return 0;
}
# include <iostream>
# include <cstdio>
# include <vector>
using namespace std;
char map[300][300];
int c,r;
void dfs(int i,int j,double &x,double &y,int &total)

{
if(i<0||i>=r||j<0||j>c||map[i][j]=='.') return;
map[i][j]='.';
total++;
x+=(2*i+1)/2.0;
y+=(2*j+1)/2.0;
dfs(i-1,j,x,y,total);
dfs(i+1,j,x,y,total);
dfs(i,j-1,x,y,total);
dfs(i,j+1,x,y,total);
}
int main()

{
while(true)
{
vector<double> x,y;
scanf("%d%d",&c,&r);
if(!c&&!r) break;
while(true)
{
int maxnum=-1;
double totalx=0,totaly=0;
for(int i=0;i<r;i++)
scanf("%s",map[i]);
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
if(map[i][j]=='x')
{
double nowx=0,nowy=0;
int total=0;
dfs(i,j,nowx,nowy,total);
if(total>maxnum)
{
maxnum=total;
totalx=nowx;
totaly=nowy;
}
}
x.push_back((totalx)/maxnum);
y.push_back((totaly)/maxnum);
scanf("%s",map[0]);
if(map[0][0]=='=') break;
}
double resx=0,resy=0;
int T=x.size()/2;
for(int i=0;i<x.size()-T;i++)
{
resx+=(x[i+T]-x[i])/T;
resy+=(y[i+T]-y[i])/T;
}
resx/=T;
resy/=T;
printf("%.2f %.2f\n",resy+1e-6,resx+1e-6);
}
return 0;
}

緇欏嚭涓涓湁n(n<=100)涓偣鐨勭畝鍗曞杈瑰艦錛屾眰璇ュ杈瑰艦鐨勯噸蹇?jī)銆?
鏍規(guī)嵁澶氳竟褰㈤噸蹇?jī)鐨勫畾涔夊Q屽彲浠ュ鍏惰繘琛屼笁瑙掑墫鍒嗭紝璁$畻姣忎釜涓夎褰㈢殑闈㈢Н浠ュ強(qiáng)閲嶅績(jī)銆傚杈瑰艦鐨勯噸蹇?jī)灏辨槸鎵鏈変笁瑙掑艦鐨勯噸蹇?jī)瀵归潰绉殑鍔犳潈邈^鍧囨暟錛屼篃灝辨槸璇達(dá)細(xì)
center.x = (cen[0].x * area[0] + cen[1].x * area[1] ..... + cen[n].x * area[n]) / totalarea
center.y = (cen[0].y * area[0] + cen[1].y * area[1] ..... + cen[n].y * area[n]) / totalarea
cen[i]浠h〃絎琲涓笁瑙掑艦鐨勯噸蹇?jī)锛屼笁瑙掑舰鐨勯噸蹇?jī)?yōu)鏄Q?
center_of_tri.x=(p1.x+p2.x+p3.x)/3.0
center_of_tri.y=(p1.y+p2.y+p3.y)/3.0
area[i]灝辨槸絎琲涓笁瑙掑艦鐨勯潰縐倀otalarea灝辨槸澶氳竟褰㈢殑鎬婚潰縐?
#include <cstdio>
#include <cmath>
#define EPS 1e-8
#define N 105
struct POINT
{
double x, y;
POINT()
{
x = y = 0;
}
POINT(double x, double y) :
x(x), y(y)
{
}
void get()
{
scanf("%lf%lf", &x, &y);
}
void print()
{
printf("%.6lf %.6lf\n", x, y);
}
POINT operator+(const POINT &p)
{
return POINT(x + p.x, y + p.y);
}
};
POINT pl[N];
int n;
double cross(POINT o, POINT &a, POINT &b)
{
return (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
}
int sgn(double x)
{
return x < -EPS ? -1 : x > EPS;
}
void solve()
{
int i;
double area = 0;
POINT ct;
for (i = 0; i < n; i++)
pl[i].get();
pl[i] = pl[0];
for (i = 0; i < n; i++)
{
double s = cross(POINT(), pl[i], pl[i + 1]);
POINT t;
area += s;
t = pl[i] + pl[i + 1];
ct.x += s * t.x, ct.y += s * t.y;
}
ct.x = ct.x / area / 3.0, ct.y = ct.y / area / 3.0;
ct.print();
}
int main()
{
int T = 1;
while (scanf("%d", &n) && n)
{
printf("Stage #%d: ", T++);
solve();
}
return 0;
}