#include <iostream>
#include <string>
using namespace std;
int main(void)
{
int m, n, k, pi;
cin >> m;
while (m--)
{
cin >> n >> k;
int address_max = 0;
int check_max = 0;
int address_min = 0;
int check_min = 0;
int max = 0;
int min = 0;
int num[102] = { 0 };
int right[52] = { 0 };
int left[52] = { 0 };
bool lock[102] = { 0 };
string input;
while (k--)
{
cin >> pi;
for (int i = 1; i <= pi; i++)
{
cin >> left[i];
}
for (int i = 1; i <= pi; i++)
{
cin >> right[i];
}
cin >> input;
if (input == "=")
{
for (int i = 1; i <= pi; i++)
{
num[left[i]] = 0;
lock[left[i]] = 1;
num[right[i]] = 0;
lock[right[i]] = 1;
}
}
else if (input == ">")
{
for (int i = 1; i <= pi; i++)
{
if (num[left[i]] >= 0 && lock[left[i]] == 0)
{
num[left[i]]++;
if (num[left[i]] > max)
{
max = num[left[i]];
}
}
else if (num[left[i]] < 0)
{
num[left[i]] = 0;
lock[left[i]] = 1;
}
}
for (int i = 1; i <= pi; i++)
{
if (num[right[i]] <= 0 && lock[right[i]] == 0)
{
num[right[i]]--;
if (min > num[right[i]])
{
min = num[right[i]];
}
}
else if (num[right[i]] > 0)
{
num[right[i]] = 0;
lock[right[i]] = 1;
}
}
}
else if (input == "<")
{
for (int i = 1; i <= pi; i++)
{
if (num[left[i]] <= 0 && lock[right[i]] == 0)
{
num[left[i]]--;
if (min > num[left[i]])
{
min = num[left[i]];
}
}
else if (num[left[i]] > 0)
{
num[left[i]] = 0;
lock[left[i]] = 1;
}
}
for (int i = 1; i <= pi; i++)
{
if (num[right[i]] >= 0 && lock[right[i]] == 0)
{
num[right[i]]++;
if (num[right[i]] > max)
{
max = num[right[i]];
}
}
else if (num[right[i]] < 0)
{
num[right[i]] = 0;
lock[right[i]] = 1;
}
}
}
}
while (check_max == 0 && max != 0)
{
for (int i = 1; i <= n; i++)
{
if (num[i] == max)
{
check_max++;
address_max = i;
}
}
if (check_max % 2 == 0)
{
check_max = 0;
}
max--;
}
while (check_min == 0 && min != 0)
{
for (int i = 1; i <= n; i++)
{
if (num[i] == min)
{
check_min++;
address_min = i;
}
}
if (check_min % 2 == 0)
{
check_min = 0;
}
min++;
}
if (max > (min * (-1)) && check_max == 1)
{
cout << address_max << endl;
}
else if (max < (min * (-1)) && check_min == 1)
{
cout << address_min << endl;
}
else
{
cout << "0" << endl;
}
cout << endl;
}
return 0;
}
卡很久了...
不知道還少考慮甚麼QQ
#include
#include
using namespace std;
int main(void)
{
int m, n, k, pi;
cin >> m;
while (m--)
{
cin >> n >> k;
int address_max = 0;
int check_max = 0;
int address_min = 0;
int check_min = 0;
int max = 0;
int min = 0;
int num[102] = { 0 };
int right[52] = { 0 };
int left[52] = { 0 };
bool lock[102] = { 0 };
string input;
while (k--)
{
cin >> pi;
for (int i = 1; i <= pi; i++)
{
cin >> left[i];
}
for (int i = 1; i <= pi; i++)
{
cin >> right[i];
}
cin >> input;
if (input == "=")
{
for (int i = 1; i <= pi; i++)
{
num[left[i]] = 0;
lock[left[i]] = 1;
num[right[i]] = 0;
lock[right[i]] = 1;
}
}
else if (input == ">")
{
for (int i = 1; i <= pi; i++)
{
if (num[left[i]] >= 0 && lock[left[i]] == 0)
{
num[left[i]]++;
if (num[left[i]] > max)
{
max = num[left[i]];
}
}
else if (num[left[i]] < 0)
{
num[left[i]] = 0;
lock[left[i]] = 1;
}
}
for (int i = 1; i <= pi; i++)
{
if (num[right[i]] <= 0 && lock[right[i]] == 0)
{
num[right[i]]--;
if (min > num[right[i]])
{
min = num[right[i]];
}
}
else if (num[right[i]] > 0)
{
num[right[i]] = 0;
lock[right[i]] = 1;
}
}
}
else if (input == "<")
{
for (int i = 1; i <= pi; i++)
{
if (num[left[i]] <= 0 && lock[right[i]] == 0)
{
num[left[i]]--;
if (min > num[left[i]])
{
min = num[left[i]];
}
}
else if (num[left[i]] > 0)
{
num[left[i]] = 0;
lock[left[i]] = 1;
}
}
for (int i = 1; i <= pi; i++)
{
if (num[right[i]] >= 0 && lock[right[i]] == 0)
{
num[right[i]]++;
if (num[right[i]] > max)
{
max = num[right[i]];
}
}
else if (num[right[i]] < 0)
{
num[right[i]] = 0;
lock[right[i]] = 1;
}
}
}
}
while (check_max == 0 && max != 0)
{
for (int i = 1; i <= n; i++)
{
if (num[i] == max)
{
check_max++;
address_max = i;
}
}
if (check_max % 2 == 0)
{
check_max = 0;
}
max--;
}
while (check_min == 0 && min != 0)
{
for (int i = 1; i <= n; i++)
{
if (num[i] == min)
{
check_min++;
address_min = i;
}
}
if (check_min % 2 == 0)
{
check_min = 0;
}
min++;
}
if (max > (min * (-1)) && check_max == 1)
{
cout << address_max << endl;
}
else if (max < (min * (-1)) && check_min == 1)
{
cout << address_min << endl;
}
else
{
cout << "0" << endl;
}
cout << endl;
}
return 0;
}
卡很久了...
不知道還少考慮甚麼QQ
提供一個測資:
5 2
1 1 4
=
1 2 5
=
如果其他硬幣都確定為真,剩下的那枚就是假的
提供一個測資:5 2
1 1 4
=
1 2 5
=如果其他硬幣都確定為真,剩下的那枚就是假的
改了!
但是還是卡住了QQ
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
int m, n, k, pi;
cin >> m;
while (m--)
{
cin >> n >> k;
int address_max = 0;
int check_max = 0;
int address_min = 0;
int check_min = 0;
int max = 0;
int min = 0;
int add = 0;
int fuck;
int num[102] = { 0 };
int right[52] = { 0 };
int left[52] = { 0 };
bool lock[102] = { 0 };
string input;
while (k--)
{
cin >> pi;
for (int i = 1; i <= pi; i++)
{
cin >> left[i];
}
for (int i = 1; i <= pi; i++)
{
cin >> right[i];
}
cin >> input;
if (input == "=")
{
for (int i = 1; i <= pi; i++)
{
num[left[i]] = 0;
lock[left[i]] = 1;
num[right[i]] = 0;
lock[right[i]] = 1;
}
}
else if (input == ">")
{
for (int i = 1; i <= pi; i++)
{
if (num[left[i]] >= 0 && lock[left[i]] == 0)
{
num[left[i]]++;
if (num[left[i]] > max)
{
max = num[left[i]];
}
}
else if (num[left[i]] < 0)
{
num[left[i]] = 0;
lock[left[i]] = 1;
}
}
for (int i = 1; i <= pi; i++)
{
if (num[right[i]] <= 0 && lock[right[i]] == 0)
{
num[right[i]]--;
if (min > num[right[i]])
{
min = num[right[i]];
}
}
else if (num[right[i]] > 0)
{
num[right[i]] = 0;
lock[right[i]] = 1;
}
}
}
else if (input == "<")
{
for (int i = 1; i <= pi; i++)
{
if (num[left[i]] <= 0 && lock[right[i]] == 0)
{
num[left[i]]--;
if (min > num[left[i]])
{
min = num[left[i]];
}
}
else if (num[left[i]] > 0)
{
num[left[i]] = 0;
lock[left[i]] = 1;
}
}
for (int i = 1; i <= pi; i++)
{
if (num[right[i]] >= 0 && lock[right[i]] == 0)
{
num[right[i]]++;
if (num[right[i]] > max)
{
max = num[right[i]];
}
}
else if (num[right[i]] < 0)
{
num[right[i]] = 0;
lock[right[i]] = 1;
}
}
}
}
while (check_max == 0)
{
for (int i = 1; i <= n; i++)
{
if (num[i] == max)
{
check_max++;
address_max = i;
}
}
max--;
if (max == 0)
{
break;
}
}
while (check_min == 0)
{
for (int i = 1; i <= n; i++)
{
if (num[i] == min)
{
check_min++;
address_min = i;
}
}
min++;
if (min == 0)
{
break;
}
}
if (max > min * (-1) && check_max == 1)
{
cout << address_max << endl;
}
else if (max < min * (-1) && check_min == 1)
{
cout << address_min << endl;
}
else
{
for (int i = 1; i <= n; i++)
{
if (lock[i] == 0)
{
add++;
fuck = i;
}
}
if (add == 1)
{
cout << fuck << endl;
}
else
{
cout << "0" << endl;
}
}
cout << endl;
}
return 0;
}
老實說我看不太懂你的程式,不過我又想到一個測資,你可以試試看:
5 2
1 1 2
>
1 1 3
=
老實說我看不太懂你的程式,不過我又想到一個測資,你可以試試看:5 2
1 1 2
>
1 1 3
=
大佬 太感謝你了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
終於寫對拉拉拉拉拉拉拉拉拉拉拉拉拉拉拉拉
感謝你提供的這兩筆測資
我會寫一份解題報告給我這種頭腦簡單的爆破仔
也會提供我那超直接的想法