杭电暑假多校集训营第八场
Clockwise or Counterclockwise
根据点C在AB向量的方位可以确定。
#include <iostream> #define ll long long using namespace std; int main(){ int n; cin>>n; int x1,y1,x2,y2,x3,y3; while(n--){ cin>>x1>>y1>>x2>>y2>>x3>>y3; ll A=x2-x1; ll B=y2-y1; ll C=x3-x1; ll D=y3-y1; ll num1=A*D; ll num2=B*C; if(num1-num2>0)cout << "Counterclockwise\n"; else cout<< "Clockwise\n"; } return 0; }
Fluctuation Limit
之前写题忘记从右向左约束,实际上应将区间从左往右,从右往左约束一篇,每个区间的范围选择上一区间(左边界减k,右边界加k)与当前区间的交集。
#include <iostream> #include <cstring> using namespace std; const int maxn=1e6+10; int l[maxn], r[maxn]; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> l[i] >> r[i]; } for (int i = 1; i < n; i++) { l[i + 1] = max(l[i + 1], l[i] - k); r[i + 1] = min(r[i + 1], r[i] + k); } for (int i = n; i > 1; i--) { l[i - 1] = max(l[i - 1], l[i] - k); r[i - 1] = min(r[i - 1], r[i] + k); } bool flag = true; for (int i = 1; i <= n; ++i) { if (l[i] > r[i]) { flag = false; } } if (flag) { cout << "YES" << endl; for (int i = 1; i <= n; ++i) { cout << l[i]; if (i < n) { cout << " "; } else { cout << endl; } } } else { cout << "NO" << endl; } } }