¼ÙÉè´æÔÚÁ½¸öÀíÂÛ½á¹ûÒ»ÖµĹ«Ê½bºÍb1:
bºÍb1µÄ¼ÆË㷽ʽÀíÂÛÉϼÆËãµÃ³öµÄ½á¹ûÊÇÒ»ÑùµÄ,±àÒëÆ÷´òÓ¡³öÀ´ÈâÑÛ¿´Ò²ÊÇÒ»ÑùµÄ,ϵͳÅж¨²»Ò»ÑùÔÒòÈçÏÂ: ¼´Ê¹doubleÓÐןܸߵľ«¶È(64λ),µ«ÊÇ»úÆ÷¶Ô×îºóһλµÄ´¦Àí±Ø¶¨ÊÇËÄÉáÎåÈëµÄ;
ÈçÓöµ½ÎÞÏÞÑ»·orÎÞÏÞ²»Ñ»·Ð¡ÊýÕâÑùµÄ¼ÆËã½á¹û,Èô½«¸Ã½á¹û±£´æÔÚij¸ödouble±äÁ¿ÖÐÓÃÓÚºóÐø¼ÆËã,¼ÆËã½á¹ûµÄÅжϿÉÄÜ»á³ö´í¡£
ÄÇôÓÐÒÔϼ¸ÖÖ´¦Àí·½Ê½: (1)½«doubleÇ¿ÖÆת»»Îªstring,±£Áô¾«¶ÈÔÚÊ®½øÖÆ0.000001 (2)¼ì²â²îÖµ,µ±²îֵСÓÚ0.000001ʱÈÏΪһÖ (3)ÍƼöµÄ°ì·¨:ÔÚ¼ÆË㹫ʽÖб£Ö¤²»°üº¬Ä³¸ödoubleÐ͵ıäÁ¿k(¸Ãk¿ÉÄÜÊǾ¹ýϵͳĩβËÄÉáÎåÈëÈ¡ÖµµÄÎÞÏÞСÊý)
¡¾½«ÏÂÃæµÄ´úÂë±£´æΪcppÎļþ²¢ÔËÐпÉÒÔ¿´µ½ÕâÖÖ³ö´íµÄÇé¿ö¡¿
# include<iostream>
# include<map>
# include<set>
# include<string>
#define row 5
#define col 3
using namespace std;
int main() {
map<pair<double, double>, int> m = {};
int ans = 0;
for (int x1 = 0; x1 < row; x1++)
for (int y1 = 0; y1 < col; y1++)
for (int x2 = 0; x2 < row; x2++)
for (int y2 = 0; y2 < col; y2++) {
if (x1 == x2 || y1 == y2) continue;
double k = 1.0*(y2 - y1) / (x2 - x1)*1.0;
double b = (y1 - k * x1);
double k1 = (y1 - y2) * 1.0 / (x1 - x2);
double b1 = ((x2 * y1 - x1 * y2) * 1.0) / ((x2 - x1) * 1.0);
if (b != b1) {
printf("µãA1:(%d,%d),\tµãA2:(%d,%d)\n", x1, y1, x2, y2);
printf("b¹«Ê½¼ÆËã³öµÄ½Ø¾à:\tÊ®Áù½øÖÆ:%x\t¸¡µãÐÍ:%lf\n", b,b);
printf("b1¹«Ê½¼ÆËã³öµÄ½Ø¾à:\tÊ®Áù½øÖÆ:%x\t¸¡µãÐÍ:%lf\n", b1,b1);
string notice = b == b1 ? "b==b1" : "b!=b1";
cout << notice << endl;
cout << " ½«Æäת»»³ÉstringÔÙ×ö±È½Ï: " << endl;
string str = to_string(b);
string str1 = to_string(b1);
cout << "str_b:\t" << str << endl;
cout << "str_b1:\t" << str1 << endl;
string note = str == str1 ? "str_b==str_b1" : "str_b!=str_b1";
cout << note << endl << endl;
}
if (m[{k, b}] == 0) {
m[{k, b}] = 1;
ans++;
}
}
cout << "ÓÉÓÚÉÏÊöÎÊÌâµ¼ÖµĽá¹û´íÎó:" << ans + row + col << endl;
cout << "__________________________________________________________________\n\n\n" << endl;
set<pair<double, double> >a;
for (int x1 = 0; x1 < row; x1++) {
for (int y1 = 0; y1 < col; y1++) {
for (int x2 = 0; x2 < row;x2++) {
for (int y2 = 0; y2 < col;y2++){
if (x1 == x2 ) {
continue;
}
double k = (y1 - y2) * 1.0 / (x1 - x2);
double b = ((x2 * y1 - x1 * y2) * 1.0) / ((x2 - x1) * 1.0);
a.insert(make_pair(k, b));
}
}
}
}
cout << "ÏßÌõµÄÕæÕý¸öÊý" << a.size() + row << endl;
return 0;
}
|