Thứ Tư, 18 tháng 11, 2020

Cho một chuỗi điều kiện, tìm số thỏa mãn chuỗi điều kiện đó

 Đề bài: $\href{https://codeforces.com/problemset/problem/416/A}{Đây}$

Tóm tắt: Cho chuỗi điều kiện, tìm số thỏa mãn chuỗi điều kiện đó

Lời giải: Chạy trâu

Source:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define maxn 10005
  5. ll n;
  6. ll l = -2000000000,r=2000000000;
  7. struct ok{
  8. string s;
  9. ll so;
  10. char c;
  11. };
  12. ok a[maxn];
  13. void check(ll i){
  14. string aka;
  15. char akaa;
  16. ll soo;
  17. aka=a[i].s;
  18. soo = a[i].so;
  19. akaa = a[i].c;
  20. if(aka.size()==1){
  21. if(aka==">"){
  22. if(akaa=='N') {r=min(r,soo);return;}
  23. if(akaa=='Y') {l=max(l,soo+1);return;}
  24. }
  25. if(aka=="<"){
  26. if(akaa=='N') {l=max(l,soo);return;}
  27. if(akaa=='Y') {r=min(r,soo-1);return;}
  28. }
  29. }
  30. if(aka.size()==2){
  31. if(aka==">="){
  32. if(akaa=='N') {r=min(r,soo-1);return;}
  33. if(akaa=='Y') {l=max(l,soo);return;}
  34. }
  35. if(aka=="<="){
  36. if(akaa=='N') {l=max(l,soo+1);return;}
  37. if(akaa=='Y') {r=min(r,soo);return;}
  38. }
  39. }
  40. }
  41. int main(){
  42. cin>>n;
  43. ll i;
  44. for(i=0;i<n;i++) cin>>a[i].s>>a[i].so>>a[i].c;
  45. for(i=0;i<n;i++){
  46. check(i);
  47. }
  48. if(l<=r) cout<<l;
  49. else cout<<"Impossible";
  50. }

Không có nhận xét nào:

Đăng nhận xét

Cho mảng A gồm n phần tử, sắp xếp lại mảng này sao cho số cặp a[i] bé hơn a[i+1] lớn nhất có thể

 Đề bài: $\href{https://codeforces.com/problemset/problem/651/B}{Đây}$  Tóm tắt:Cho một mảng gồm n phần tử, hãy sắp xếp lại mảng theo thứ tự...