CF B题,每日一道练习思维的流畅和切题的速度
10.18
一道几何相关的模拟
#include <bits/stdc++.h>
#define yes puts("yes");
#define inf 0x3f3f3f3f
#define ll long long
#define linf 0x3f3f3f3f3f3f3f3f
#define debug(x) cout<<"> "<< x<<endl;
#define ull unsigned long long
#define endl '\n'
#define lowbit(x) x&-x
//#define int long long
using namespace std;
typedef pair<int,int> PII;
const int N =10 + 1e5 ,mod=1e9 + 7;
void solve()
{
double W,H;
double x1,x2,y1,y2;
double w,h;
cin>>W>>H;
cin>>x1>>y1>>x2>>y2;
cin>>w>>h;
double res = 1e9;
if(x2 - x1 + w <= W){
res = min(res,max(0.0,w - x1));
res = min(res,max(0.0,x2 - (W - w)));
}
if(y2 - y1 + h <= H){
res = min(res,max(0.0,h - y1));
res = min(res, max(0.0,y2 - (H - h)));
}
if(res == 1e9) cout << -1 << endl;
else cout << fixed << setprecision(10)<< res << endl;
// 缺少将无关变量排除的能力,比如本题应该把长和宽分开进行考虑 脑海中想象的是在一维数轴上点的移动而不是在一个二维平面上的移动。
// 很多时候善用min和max,可以减少很多if判断,一般出现的场景是当某个数值超出某种限制后,会返回一个0一类的数值,比如本题就是
// 正负的限制,最终返回 0。
}
signed main()
{
ios::sync_with_stdio();cin.tie();cout.tie();
int T;cin>>T;
while(T--)
solve();
return 0;
}
10.19
#include <bits/stdc++.h>
#define yes puts("yes");
#define inf 0x3f3f3f3f
#define ll long long
#define linf 0x3f3f3f3f3f3f3f3f
#define debug(x) cout<<"> "<< x<<endl;
#define ull unsigned long long
#define endl '\n'
#define lowbit(x) x&-x
//#define int long long
using namespace std;
typedef pair<int,int> PII;
const int N =10 + 1e5 ,mod=1e9 + 7;
void solve()
{
int n;
cin>>n;
string s;
cin >> s;
int id0 = n,id1 = -1;
for(int i=0;i<n;i++){
if(s[i] == '1'){
id1 = i;
break;
}
}
for(int i=n-1;i>=0;i--){
if(s[i] == '0'){
id0 = i;
break;
}
}
if(id0 == n || id1 == -1 || id1 > id0){
for(auto it:s)
cout << it;
cout << endl;
}else{
for(int i=0;i<id1;i++)
cout << s[i];
cout << '0';
for(int i=id0 + 1;i< n;i++)
cout << s[i];
cout << endl;
}
// 十五分钟内干出来了 , 但是中间仍然有很多无效思考
// 最有效的思考应该从10出发,发现在这个字符串中加如任何东西,最后都可以被化归为原来的10串,发现这点 问题迎刃而解
// 可以启发 思考应该更加紧密的建立在题中给出的某些小部件上的扩充 而不是脑中随机构造例子
// 重点是在题中给出的条件上构建出例子,这有助于发现问题的本质。
}
signed main()
{
ios::sync_with_stdio();cin.tie();cout.tie();
int T;cin>>T;
while(T--)
solve();
return 0;
}
10.22
忙 不发代码了.