锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
瀵逛竴涓鏁存暟 n 錛屽鏋?n 鍦ㄦ暟鎹枃浠朵腑鏌愯鐨勪袱涓鏁存暟錛堝亣璁句負 A 鍜?B 錛変箣闂達紝鍗?A<=n<=B 鎴?A>=n>=B 錛屽垯 n 灞炰簬璇ヨ錛涘鏋?n 鍚屾椂 灞炰簬琛?i 鍜?j 錛屽垯 i 鍜?j 鏈夐噸鍙犲尯闂達紱閲嶅彔鍖洪棿鐨勫ぇ灝忔槸鍚屾椂灞炰簬琛?i 鍜?j 鐨勬暣鏁頒釜鏁般?nbsp;
渚嬪錛岃錛?10 20 錛夊拰錛?12 25 錛夌殑閲嶅彔鍖洪棿涓?[12 20] 錛屽叾澶у皬涓?9 錛涜錛?20 10 錛夊拰錛?12 18 錛夌殑閲嶅彔鍖洪棿涓?[10 12] 錛屽叾澶у皬涓?3 錛涜 (20 10) 鍜岋紙 20 30 錛夌殑閲嶅彔鍖洪棿澶у皬涓?1 銆?br>
杈撳叆鏁版嵁錛氱▼搴忚鍏ュ凡琚懡鍚嶄負 input.txt 鐨勮緭鍏ユ暟鎹枃鏈枃浠訛紝璇ユ枃浠剁殑琛屾暟鍦?1 鍒?1,000,000 涔嬮棿錛屾瘡琛屾湁鐢ㄤ竴涓┖鏍煎垎闅旂殑 2 涓鏁存暟錛岃繖 2 涓鏁存暟鐨勫ぇ灝忔搴忛殢鏈猴紝姣忎釜鏁伴兘鍦?1 鍜?2^32-1 涔嬮棿銆傦紙涓轟究浜庤皟璇曪紝鎮ㄥ彲涓嬭澆嫻嬭瘯 input.txt 鏂囦歡錛屽疄闄呰繍琛屾椂鎴戜滑浼氫嬌鐢ㄤ笉鍚屽唴瀹圭殑杈撳叆鏂囦歡銆傦級
杈撳嚭鏁版嵁錛氬湪鏍囧噯杈撳嚭涓婃墦鍗板嚭杈撳叆鏁版嵁鏂囦歡涓渶澶ч噸鍙犲尯闂寸殑澶у皬錛屽鏋滄墍鏈夎閮芥病鏈夐噸鍙犲尯闂達紝鍒欒緭鍑?0 銆?
璇勫垎鏍囧噯錛氱▼搴忚緭鍑虹粨鏋滃繀欏繪紜紝鍐呭瓨浣跨敤蹇呴』涓嶈秴榪?256MB 錛岀▼搴忕殑鎵ц鏃墮棿瓚婂揩瓚婂ソ銆?
2 #include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
typedef struct {int x,y,l;} Sec;
const int MAXN= 1000003;
int n,l;
Sec sec[MAXN];
int cmp(const void *a,const void *b)
{
return (*((Sec *)a)).x-(*((Sec *)b)).x;
}
int main()
{
int i,j,k,t;
freopen("input.txt","r",stdin);
n=0,l=0;
while(scanf("%d%d",&sec[n].x,&sec[n].y)!=EOF)
{
if(sec[n].x>sec[n].y) t=sec[n].x,sec[n].x=sec[n].y,sec[n].y=t;
sec[n].l=sec[n].y-sec[n].x+1;
n++;
}
qsort(sec,n,sizeof(Sec),cmp);
for(i=0;i<n;i++)
{
if(sec[i].x == -1) continue;
for(j=i+1;j<n;j++)
{
if(sec[j].x > sec[i].y) break; //鑲畾涓嶄細閲嶅彔
if(sec[j].x == -1 || sec[j].y>sec[i].y) continue;
if(sec[j].l>l) l=sec[j].l;//sec[i]瀹屽叏鍖呮嫭sec[j]
sec[j].x = -1; //宸茬粡鑰冭檻榪?br> }
}
for(i=0;i<n;i++)
{
if(sec[i].x == -1) continue;
for(j=i+1;j<n;j++)
{
if(sec[j].x > sec[i].y) break;
if(sec[j].x == -1) continue;
if(sec[i].y - sec[j].x +1 >l) l =sec[i].y-sec[j].x+1;
break;
}
}
cout<<l<<endl;
return 0;
}
]]>
鎴戜滑涓鑸垽鏂竴涓瓧鏄惁鏄眽瀛楅兘鏄牴鎹叾棣栧瓧鑺傛潵鍒ゆ柇錛屾垜浠潵鐪嬫眽瀛楃殑GBK緙栫爜棣栧瓧鑺傜殑璧峰緙栫爜0x81錛屽叾浜岃繘鍒跺嵆涓?000 1000 0000 0000錛?鍙鑻ヤ竴涓瓧絎︾殑浜岃繘鍒墮昏緫涓?x81涔嬪悗涓?鏃訛紝璇ュ瓧絎︿竴瀹氬皬浜?x81錛屾鏃惰瀛楃蹇呭畾涓嶆槸姹夊瓧錛屽弽涔嬶紝璇ュ瓧絎﹀簲璇ユ槸涓涓眽瀛楃殑棣栧瓧鑺傘?/p>
緇撳悎浠ヤ笂鍘熺悊灝變笉闅劇悊瑙d竴涓腑鑻辨枃娣峰悎瀛楃涓茬殑鎴彇鐨勫父鐢ㄤ唬鐮侊細
function gb_substr($str, $start, $len)
{
$s = '';
$j = 0;
for ($i=0; $i<strlen($str); $i++) {
if (ord($str[$i]) & 0x81 != 0) { //鎴栬卭rd($str[$i]) > '0x80'
$t = $str[$i].$str[$i+1];
if (($i >= $start) && ($i+1 < $start+$len)) $s.= $t;
$i++;
} else {
$t = $str[$i];
if (($i >= $start) && ($i < $start+$len)) $s.= $t;
}
if ($i >= $start+$len) break;
}
return $s;
}
濡傚浘錛屼竴涓崐寰勪負1鐨勫渾鍛ㄤ笂鏈?/span>5涓偣銆傛寜瑙掑害鍒剁粰鍑?/span>5涓偣鐨勬瀬瑙?/span>Ai (0<=Ai<360, i=1..5)銆傛寜涓嬪浘鐨勬柟娉曡繛鎴愪竴涓簲瑙掓槦, 璁$畻鍦嗚鍒囧壊鎴愮殑11涓儴鍒嗛潰縐殑鏂瑰樊銆?/span>
鍏蜂綋鍦拌, 鍋囧畾11涓尯鍩熺殑闈㈢Н鍒嗗埆涓?/span>S1,S2, ..., S11錛岄偅涔堥潰縐殑鍧囧艱綆楁柟娉曚負錛?/span>
M = (S1+S2+...+S11 ) / 11
闈㈢Н鐨勬柟宸綆楁柟娉曚負錛?/span>
D = ((S1-M)2 + (S2-M)2 + ... + (S11-M)2) / 11
杈撳叆鏍煎紡
杈撳叆浠呬竴琛岋紝鍖呭惈5涓?/span>[0,359]鍐呯殑浜掍笉鐩哥瓑鐨勬暣鏁般?/span>
杈撳嚭鏍煎紡
杈撳嚭浠呬竴琛岋紝鍖呭惈涓涓疄鏁幫紝鍗沖悇閮ㄥ垎闈㈢Н鐨勬柟宸傝緭鍑轟繚鐣欏皬鏁扮偣鍚?/span>4浣嶃?/span>
鏍蜂緥杈撳叆
0 144 72 288 216
鏍蜂緥杈撳嚭
0.0144
鎴戝闂鐨勫垎鏋?/strong>錛?/font>
1銆佹妸鏋佽鎺掑簭錛堟湁鍒╀簬鍚庣畫璁$畻錛夛紝杞寲涓虹洿瑙掑潗鏍囩郴鍧愭爣
2銆佹眰浜旇鏄熷唴浜ょ偣浜斾釜
3銆佹眰浜斾釜涓槦欏朵笁瑙掑艦闈㈢Н
4銆佹眰鍑?#8220;寮撳艦-涓夎褰?#8221;闈㈢Н錛岀劧鍚庝互浜斾釜灝忔墖褰負鏈煡閲忚В涓涓簲鍏冪嚎鎬ф柟紼嬬粍錛屾眰鍑轟簲涓皬鎵囧艦闈㈢Н
5銆佺敱鍦嗙殑闈㈢Н鍑忓幓姹傚嚭鐨勫崄涓潰縐紝寰楀埌閲嶅績鐨勪簲杈瑰艦闈㈢Н
6銆佹牴鎹柟宸叕寮忔眰鍑虹瓟妗?/font>
銆愯瘎浠楓戣繖涓柟娉曞熀鏈睘浜庢寜閮ㄥ氨鐝殑鏂規硶錛屽洜涓烘病鏈夊彂鎺樺埌鍦嗗唴鎺ヤ簲瑙掓槦鐨勭壒孌婃ц川錛屾墍浠ュ茍娌℃湁娑夊強鍒頒粈涔堟妧宸с?/font>
鎴戠殑浠g爜
#include <stdio.h>#include <stdlib.h> #include <math.h> #define PI 3.1415926535898 typedef struct POINT { double x; double y; }Point,*lpPoint;//鐐瑰潗鏍? struct COMB { POINT p; POINT PL;//宸︿氦鐐? POINT PR;//鍙充氦鐐? };//浜旂鐐圭殑闄勫甫緇撴瀯 COMB c[5];//緇撴瀯鏁扮粍 int arg[5];//瑙掑害 double areaG[5];//寮撳艦 double area[11];//11涓儴鍒嗛潰縐? //閫夋嫨鎺掑簭 void sort(int arr[], int n) { int i, j, min, t; for (i = 0; i < n -1; i++) { min = i; for (j = i + 1; j < n; j++) { if (arr[min] > arr[j]) { min = j; } } if (min != i) { t = arr[i]; arr[i] = arr[min]; arr[min] = t; } } } //涓ょ嚎孌典氦鐐? POINT GetCrossPoint(POINT p1, POINT p2, POINT q1, POINT q2) { /*鏍規嵁涓ょ偣寮忓寲涓烘爣鍑嗗紡錛岃繘鑰屾眰綰挎ф柟紼嬬粍*/ POINT crossPoint; double tempLeft,tempRight; //姹倄鍧愭爣 tempLeft = (q2.x - q1.x) * (p1.y - p2.y) - (p2.x - p1.x) * (q1.y - q2.y); tempRight = (p1.y - q1.y) * (p2.x - p1.x) * (q2.x - q1.x) + q1.x * (q2.y - q1.y) * (p2.x - p1.x) - p1.x * (p2.y - p1.y) * (q2.x - q1.x); crossPoint.x =tempRight /tempLeft; //姹倅鍧愭爣 tempLeft = (p1.x - p2.x) * (q2.y - q1.y) - (p2.y - p1.y) * (q1.x - q2.x); tempRight = p2.y * (p1.x - p2.x) * (q2.y - q1.y) + (q2.x- p2.x) * (q2.y - q1.y) * (p1.y - p2.y) - q2.y * (q1.x - q2.x) * (p2.y - p1.y); crossPoint.y =tempRight / tempLeft; return crossPoint; } //姹傛墍鏈変氦鐐? void cross() { int i; for (i=0;i<5;i++) { c[i].PL = GetCrossPoint(c[i].p,c[(i+3)%5].p,c[(i+1)%5].p,c[(i+4)%5].p); c[(i+4)%5].PR = c[i].PL; } } //void Helen(); //double SideLength(POINT X,POINT Y); //鐐瑰埌鐐圭殑璺濈 double SideLength( POINT X,POINT Y ) { double r=sqrt(((X.x-Y.x)*(X.x-Y.x)+(X.y-Y.y)*(X.y-Y.y))); return r; } //嫻蜂雞鍏紡姹備笁瑙掑艦闈㈢Н void Helen() { double a,b,d; //涓夎竟闀? double p; //騫沖潎鍊? for (int i=0; i<5; i++) { a=SideLength(c[i].p,c[i].PL); b=SideLength(c[i].PR,c[i].PL); d=SideLength(c[i].p,c[i].PR); p=0.5*(a+b+d); area[i]=sqrt((p*(p-a)*(p-b)*(p-d))); } } //姹備簲涓紦褰㈤潰縐? void Arch() { double x; double arc; double rui; for (int i=0;i<5;i++) { x=0.5*SideLength(c[(i+4)%5].p,c[(i+1)%5].p); rui = acos(x); arc=PI-2.0*acos(x); areaG[i]=0.5*arc-0.5*sin(arc); } } //瑙f柟紼嬫眰寮ц竟鐨勪簲鍧楀皬鎵囧艦闈㈢Н void Equation() { double temp[5]; //寮撳艦鍑忓幓涓夎(鏂圭▼鍙寵竟) for (int i=0; i<5; i++) { temp[i] = areaG[i] - area[i]; } //姹傝В area[5] = (temp[0]+temp[2]+temp[4]-temp[1]-temp[3])/2; area[6] = (temp[0]+temp[1]+temp[3]-temp[2]-temp[4])/2; area[7] = (temp[1]+temp[2]+temp[4]-temp[0]-temp[3])/2; area[8] = (temp[0]+temp[2]+temp[3]-temp[1]-temp[4])/2; area[9] = (temp[1]+temp[3]+temp[4]-temp[0]-temp[2])/2; } //姹傛渶鍚庝腑闂翠竴鍧楅潰縐? void LastArea() { double plus(0.0); for (int i=0;i<10;i++) { plus += area[i]; } area[10] = PI - plus; } int main(void) { int i; for (i=0;i<5;i++) { scanf("%d",&arg[i]); } sort(arg,5);//鎺掑簭 double d[5]; for (i=0;i<5;i++) { d[i] = (double)(arg[i])*PI/180.0; } //鐐瑰潗鏍? for (i=0;i<5;i++) { c[i].p.x = cos(d[i]); c[i].p.y = sin(d[i]); } //姹傛墍鏈変氦鐐? cross(); //----------姹傞潰縐?------------- Helen();//浜斾釜涓夎褰㈤潰縐? Arch();//寮撳艦闈㈢Н Equation();//瑙f柟紼嬫眰寮ц竟鐨勪簲鍧楀皬鎵囧艦闈㈢Н LastArea();//姹傛渶鍚庝腑闂翠竴鍧楅潰縐? //瀵筧rea[11]姹傛柟宸? double aver = PI/11.0; //printf("%.4f\n",aver); double result = 0.0;//鍔犲拰 for (i=0;i<11;i++) { result = result + (area[i]-aver)*(area[i]-aver); } result = result/11.0; result = (float)((int)(result*10000+0.5))/10000.0;//鍥涜垗浜斿叆鍙栧洓浣? printf("%.4f\n",result); return 0; }
typedef map<string,int>::iterator mit;
typedef string::size_type sit;
int main()
{
map<string,int> words_count;
vector<string> sve;
string word;
string s=",!?.:""\n;'";
ifstream fin("E:\\corpus.txt");
if(!fin)
{
cerr<<"unable to open file"<<endl;
exit(0);
}
//璇誨彇騫剁粺璁″崟璇嶅崟璇?
while(fin>>word)
{
sit iter=word.find_first_of(s);
if(iter!=string::npos)
word=word.substr(0,iter-0); //澶勭悊鏍囩偣絎﹀彿
string temp(strlwr(const_cast<char*>(word.c_str())));
word=temp;
sve.push_back(word);
++words_count[word];
}
fin.close();
//鍒犻櫎涓暟鏈灝戠殑鍗曡瘝
mit i=words_count.begin();
int n=i->second;
for(;i!=words_count.end();++i)
if(i->second<n) n=i->second;
for(mit i=words_count.begin();i!=words_count.end(); )
{
if(i->second==n)
{
sve.erase(remove(sve.begin(),sve.end(),i->first),sve.end());
++i;
}
else ++i;
}
//杈撳嚭鍒板睆騫?br>copy(sve.begin(),sve.end(),ostream_iterator<string>(cout," "));
cout<<endl;
system("pause");
return 0;
}
杈撳叆鏁版嵁錛氱▼搴忚鍏ュ凡琚懡鍚嶄負text.txt鍜宒ict.txt鐨勪袱涓緭鍏ユ暟鎹枃鏈枃浠訛紝text.txt涓轟竴涓寘鍚ぇ閲忓瓧絎︿覆錛堝惈涓枃錛夌殑鏂囨湰錛屼互whitespace涓哄垎闅旂錛沝ict.txt涓鴻〃紺哄瓧絎︿覆錛坰1錛変笌瀛楃涓詫紙s2錛夌殑瀵瑰簲鍏崇郴鐨勫彟涓涓枃鏈紙鍚腑鏂囷級錛屽ぇ綰﹀湪1涓囪宸﹀彸錛屾瘡琛屼袱涓瓧絎︿覆錛堝嵆s1鍜宻2錛夛紝鐢ㄤ竴涓猏t鎴栫┖鏍煎垎闅斻俤ict.txt涓悇琛岀殑s1娌℃湁鎺掑簭錛屽茍鏈夊彲鑳芥湁閲嶅錛岃繖鏃朵互鏈鍚庡嚭鐜扮殑閭fs1鎵瀵瑰簲鐨剆2涓哄噯銆倀ext.txt鍜宒ict.txt涓殑姣忎釜瀛楃涓查兘鍙兘鍖呭惈闄hitespace涔嬪鐨勪換浣曞瓧絎︺倀ext.txt涓殑瀛楃涓插繀欏誨拰dict.txt涓殑鏌恠1瀹屽叏鍖歸厤鎵嶈兘琚浛鎹€傦紙涓轟究浜庤皟璇曪紝鎮ㄥ彲涓嬭澆嫻嬭瘯text.txt鍜宒ict.txt鏂囦歡錛屽疄闄呰繍琛屾椂鎴戜滑浼氫嬌鐢ㄤ笉鍚屽唴瀹圭殑杈撳叆鏂囦歡銆傦級
杈撳嚭鏁版嵁錛氬湪鏍囧噯杈撳嚭涓婃墦鍗皌ext.txt琚玠ict.txt鏇挎崲鍚庝簡鐨勬暣涓枃鏈?/font>
璇勫垎鏍囧噯錛氱▼搴忚緭鍑虹粨鏋滃繀欏繪紜紝鍐呭瓨浣跨敤瓚婂皯瓚婂ソ錛岀▼搴忕殑鎵ц鏃墮棿瓚婂揩瓚婂ソ銆侾S錛?font size=3>c_str()榪斿洖涓涓畠鑷繁鐨勪嬌鐢ㄥ唴瀛樼殑鍦板潃錛堜竴涓狢-STYLE鐨剆tring鈥斺旓級
浼氳嚜鍔ㄧ粰鏈鍚庢坊涓婁竴涓?\0'緇撴潫絎﹀彿
#include<iostream>
#include<fstream>
#include<string>
#include<map>
using namespace std;
map<string,string>dic;
int main()
{
string s,a,b;
char c;
fstream file("dict.txt");
while (file>>a>>b)
dic[a]=b;
file.close();
freopen("text.txt","r",stdin);
while (scanf("%c",&c)+1)
{
if (c&128)
{
s+=c;
scanf("%c",&c);
}
if ((c&128)==0&&isspace(c))
{
if (!s.empty())
if (dic[s]!="")
printf("%s",dic[s].c_str());
else
printf("%s",s.c_str());
printf("%c",c);
s="";
}
else
s+=c;
}
if (!s.empty())
if (dic[s]!="")
printf("%s",dic[s].c_str());
else
printf("%s",s.c_str());
return 0;
}