Niestety, nie byliśmy w stanie w pełni poprawnie wyświetlić tego pliku, ponieważ nie jest zakodowany w UTF-8.
Możesz pobrać ten plik i spróbować otworzyć go samodzielnie.
#include <cstdio> #include <vector> #include <algorithm> #pragma warning (disable : 4996) using namespace std; typedef long long LL; struct EvP { int t; int pm; int v; bool operator < (const EvP &that) { return this->t < that.t || this->t == that.t && this->pm < that.pm; } bool operator <= (const EvP &that) { return this->t < that.t || this->t == that.t && this->pm <= that.pm; } EvP(int t_, int pm_, int v_) : t(t_), pm(pm_), v(v_) { } ; }; int main() { #ifdef _DEBUG freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif int TEST_NUM; scanf("%d", &TEST_NUM); for(int the_test = 0; the_test < TEST_NUM; the_test++) { int n; scanf("%d", &n); vector<EvP> heat_in, heat_out; long long tot_heat_have = 0LL, tot_heat_need = 0LL; for(int i=0; i<n; i++) { int vol, t_start, t_finish; scanf("%d %d %d", &vol, &t_start, &t_finish); tot_heat_have += (LL)vol * (LL)t_start; tot_heat_need += (LL)vol * (LL)t_finish; if(t_start < t_finish) { heat_in.push_back(EvP(t_start, +1, vol)); heat_in.push_back(EvP(t_finish, -1, vol)); } else if(t_start > t_finish) { heat_out.push_back(EvP(t_start, -1, vol)); heat_out.push_back(EvP(t_finish, +1, vol)); } // if t_start == t_finish, we completely skip this cup }; if(tot_heat_have != tot_heat_need) { printf("NIE\n"); continue; } if(heat_in.empty() ^ heat_out.empty()) { // this is probably already checked by previuos if, but I still have some doubts... printf("NIE\n"); continue; } sort(heat_in.begin(), heat_in.end()); sort(heat_out.begin(), heat_out.end()); size_t i_in = 0, i_out = 0; int prev_t = min(heat_in[0].t, heat_out[0].t); LL curr_hpd_in = 0LL, curr_hpd_out = 0LL; LL curr_heat_left = 0LL; bool was_breaked = false; while(i_in < heat_in.size() || i_out < heat_out.size()) { int curr_t; if(i_out >= heat_out.size() || i_in < heat_in.size() && heat_in[i_in] <= heat_out[i_out]) { curr_t = heat_in[i_in].t; curr_heat_left += (curr_t - prev_t) * (curr_hpd_out - curr_hpd_in); curr_hpd_in += heat_in[i_in].v * heat_in[i_in].pm; i_in++; } else if(i_in >= heat_in.size() || i_out < heat_out.size() && heat_out[i_out] <= heat_in[i_in]){ curr_t = heat_out[i_out].t; curr_heat_left += (curr_t - prev_t) * (curr_hpd_out - curr_hpd_in); curr_hpd_out += heat_out[i_out].v * heat_out[i_out].pm; i_out++; #ifdef _DEBUG } else { _DEBUG_ERROR("Why is this possible?!?"); #endif } if(curr_heat_left > 0LL) { was_breaked = true; printf("NIE\n"); break; } prev_t = curr_t; } if(!was_breaked) { printf("TAK\n"); } } } /************************************* #include <cstdio> #include <vector> #include <algorithm> using namespace std; typedef pair<int,int> pii; typedef long long LL; int main() { #ifdef _DEBUG freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif int TEST_NUM; scanf("%d", &TEST_NUM); for(int the_test = 0; the_test < TEST_NUM; the_test++) { int n; scanf("%d", &n); vector<pii> have(n), need(n); long long tot_heat_have = 0LL, tot_heat_need = 0LL; long long tot_volume = 0LL; for(int i=0; i<n; i++) { scanf("%d %d %d", &(have[i].second), &(have[i].first), &(need[i].first)); need[i].second = have[i].second; tot_heat_have += (LL)have[i].first * (LL)have[i].second; tot_heat_need += (LL)need[i].first * (LL)need[i].second; tot_volume += have[i].second; }; if(tot_heat_have != tot_heat_need) { printf("NIE\n"); continue; } sort(have.begin(), have.end()); sort(need.begin(), need.end()); long long curr_heat_have = 0LL, curr_heat_need = 0LL; /// long long curr_vol_have = 0LL, curr_vol_need = 0LL; int i_have=0, i_need=0; double overall_mid_temp = tot_heat_have / tot_volume; bool was_breaked = false; while(i_have < n && i_need < n) { int curr_temp = min(have[i_have].first, need[i_need].first); while(i_have < n && have[i_have].first == curr_temp) { curr_heat_have += (LL)have[i_have].first * (LL)have[i_have].second; /// curr_vol_have += have[i_have].second; i_have++; } while(i_need < n && need[i_need].first == curr_temp) { curr_heat_need += (LL)need[i_need].first * (LL)need[i_need].second; /// curr_vol_need += need[i_need].second; i_need++; } // TODO: �����������, ��� ������� ����������� "� ������" ���������/��������� // (��� ����, ����������� �� ����, �� ����� ��������� ����������� ���-���� �����, � �� ����) /// if(curr_vol_need >= curr_vol_have && curr_heat_need < curr_heat_have) { if(curr_heat_need < curr_heat_have) { printf("NIE\n"); was_breaked = true; break; } } if(!was_breaked) { printf("TAK\n"); } } return 0; } *****************************************************/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | #include <cstdio> #include <vector> #include <algorithm> #pragma warning (disable : 4996) using namespace std; typedef long long LL; struct EvP { int t; int pm; int v; bool operator < (const EvP &that) { return this->t < that.t || this->t == that.t && this->pm < that.pm; } bool operator <= (const EvP &that) { return this->t < that.t || this->t == that.t && this->pm <= that.pm; } EvP(int t_, int pm_, int v_) : t(t_), pm(pm_), v(v_) { } ; }; int main() { #ifdef _DEBUG freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif int TEST_NUM; scanf("%d", &TEST_NUM); for(int the_test = 0; the_test < TEST_NUM; the_test++) { int n; scanf("%d", &n); vector<EvP> heat_in, heat_out; long long tot_heat_have = 0LL, tot_heat_need = 0LL; for(int i=0; i<n; i++) { int vol, t_start, t_finish; scanf("%d %d %d", &vol, &t_start, &t_finish); tot_heat_have += (LL)vol * (LL)t_start; tot_heat_need += (LL)vol * (LL)t_finish; if(t_start < t_finish) { heat_in.push_back(EvP(t_start, +1, vol)); heat_in.push_back(EvP(t_finish, -1, vol)); } else if(t_start > t_finish) { heat_out.push_back(EvP(t_start, -1, vol)); heat_out.push_back(EvP(t_finish, +1, vol)); } // if t_start == t_finish, we completely skip this cup }; if(tot_heat_have != tot_heat_need) { printf("NIE\n"); continue; } if(heat_in.empty() ^ heat_out.empty()) { // this is probably already checked by previuos if, but I still have some doubts... printf("NIE\n"); continue; } sort(heat_in.begin(), heat_in.end()); sort(heat_out.begin(), heat_out.end()); size_t i_in = 0, i_out = 0; int prev_t = min(heat_in[0].t, heat_out[0].t); LL curr_hpd_in = 0LL, curr_hpd_out = 0LL; LL curr_heat_left = 0LL; bool was_breaked = false; while(i_in < heat_in.size() || i_out < heat_out.size()) { int curr_t; if(i_out >= heat_out.size() || i_in < heat_in.size() && heat_in[i_in] <= heat_out[i_out]) { curr_t = heat_in[i_in].t; curr_heat_left += (curr_t - prev_t) * (curr_hpd_out - curr_hpd_in); curr_hpd_in += heat_in[i_in].v * heat_in[i_in].pm; i_in++; } else if(i_in >= heat_in.size() || i_out < heat_out.size() && heat_out[i_out] <= heat_in[i_in]){ curr_t = heat_out[i_out].t; curr_heat_left += (curr_t - prev_t) * (curr_hpd_out - curr_hpd_in); curr_hpd_out += heat_out[i_out].v * heat_out[i_out].pm; i_out++; #ifdef _DEBUG } else { _DEBUG_ERROR("Why is this possible?!?"); #endif } if(curr_heat_left > 0LL) { was_breaked = true; printf("NIE\n"); break; } prev_t = curr_t; } if(!was_breaked) { printf("TAK\n"); } } } /************************************* #include <cstdio> #include <vector> #include <algorithm> using namespace std; typedef pair<int,int> pii; typedef long long LL; int main() { #ifdef _DEBUG freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif int TEST_NUM; scanf("%d", &TEST_NUM); for(int the_test = 0; the_test < TEST_NUM; the_test++) { int n; scanf("%d", &n); vector<pii> have(n), need(n); long long tot_heat_have = 0LL, tot_heat_need = 0LL; long long tot_volume = 0LL; for(int i=0; i<n; i++) { scanf("%d %d %d", &(have[i].second), &(have[i].first), &(need[i].first)); need[i].second = have[i].second; tot_heat_have += (LL)have[i].first * (LL)have[i].second; tot_heat_need += (LL)need[i].first * (LL)need[i].second; tot_volume += have[i].second; }; if(tot_heat_have != tot_heat_need) { printf("NIE\n"); continue; } sort(have.begin(), have.end()); sort(need.begin(), need.end()); long long curr_heat_have = 0LL, curr_heat_need = 0LL; /// long long curr_vol_have = 0LL, curr_vol_need = 0LL; int i_have=0, i_need=0; double overall_mid_temp = tot_heat_have / tot_volume; bool was_breaked = false; while(i_have < n && i_need < n) { int curr_temp = min(have[i_have].first, need[i_need].first); while(i_have < n && have[i_have].first == curr_temp) { curr_heat_have += (LL)have[i_have].first * (LL)have[i_have].second; /// curr_vol_have += have[i_have].second; i_have++; } while(i_need < n && need[i_need].first == curr_temp) { curr_heat_need += (LL)need[i_need].first * (LL)need[i_need].second; /// curr_vol_need += need[i_need].second; i_need++; } // TODO: �����������, ��� ������� ����������� "� ������" ���������/��������� // (��� ����, ����������� �� ����, �� ����� ��������� ����������� ���-���� �����, � �� ����) /// if(curr_vol_need >= curr_vol_have && curr_heat_need < curr_heat_have) { if(curr_heat_need < curr_heat_have) { printf("NIE\n"); was_breaked = true; break; } } if(!was_breaked) { printf("TAK\n"); } } return 0; } *****************************************************/ |