»Ë»Ñ Æ÷·³
°³¹ßÀÚÆ÷·³ ÀÔ´Ï´Ù.
  • ºÏ¸¶Å© ¾ÆÀÌÄÜ

C++ ÀßÇϽô ºÐµé µµ¿ÍÁÖ¼¼¿ä¤Ð¤Ì¤Ð1

  • [* ºñȸ¿ø *]
  • µî·ÏÀÏ 2017-09-24 22:05
  • Á¶È¸¼ö 762
ÇöÀç °úÁ¦ÁßÀε¥ ÀÚ²Ù·±Å¸ÀÓ ¿¡·¯³ª¿Í¿ä¤Ð¤Ì¤Ð µµ´ëü ¹¹°¡ ¹®Á¦ÀÎÁö ¸ð¸£°Ú½À´Ï´Ù. (äÁ¡¼­¹ö¿¡¼­ Á¦ÃâÇÏ¸é ·±Å¸ÀÓ¿¡·¯°¡ ³ª¿À°í Á¦ pc¿¡¼­´Â ¸ÖÂÄÇÕ´Ï´Ù, ¾Æ¸¶ input°ª¿¡¼­ ·±Å¸ÀÓ¿¡·¯°¡ ³ª´Â°Í°°½À´Ï´Ù.)

#include
#include
#include

using namespace std;

int S[1000000];
int ST[100000000];

int main() {
ifstream inStream("input.txt");
int numCases;
int N;
int T;
int num;
int K;
int Snum;
int SUM;

inStream >> numCases;

for (int i = 0; i < numCases; i++) {//TestCase ¸¸Å­ ¹Ýº¹<br /> int total_num = 0;
int ST_num = 0;
int *ST_ptr = ST;
int count = 0;
inStream >> N;
num = N;
inStream >> T;
K = T;
for (int j = 0; j < N; j++) { // SÀÇ ¿ø¼ÒµéÀ» input<br /> inStream >> Snum;
S[j] = Snum;
}
for (int a = 0; a < num; a++) {<br /> for (int b = a + 1; b < num; b++) {<br /> SUM = K - (S[a] + S[b]);
if (SUM < 0) SUM = SUM*(-1);<br /> ST_ptr[ST_num] = SUM;
ST_num++;
}
}
if (num > 1) {
total_num = (num*(num - 1)) / 2;
}
sort(ST, ST+total_num);
for (int c = 0; c < total_num;) {<br /> if (ST[c] > ST[0]) break;
count++;
c++;
}
cout << count << endl;<br />
}
return 0;
}

Âü°í·Î input °ªÀº 2<=N<=1000000, -10^8 <=K <= 10^8 , -10^8 <=Snum <= 10^8 ÀÔ´Ï´Ù.¤Ð¤Ì¤Ð ºÎŹµå·Á¿ä¤Ð¤Ì<br /> +±Û¿¡¼­´Â ¾Èº¸À̴µ¥ include´Â iostream fstream algorithm ¼¼°¡Áö Çß½À´Ï´Ù.

0
ÃßõÇϱ⠴ٸ¥ÀÇ°ß 0
|
°øÀ¯¹öÆ°

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 ¤±¤µ¤·¤§¤¾¤µ
  • ¾Ë¸² ¿å¼³, »óó ÁÙ ¼ö ÀÖ´Â ¾ÇÇÃÀº »ï°¡ÁÖ¼¼¿ä.
©¹æ »çÁø  
¡â ÀÌÀü±Û¡ä ´ÙÀ½±Û