其实吧=-=好多题不是我自己做的贼菜
A - 函数求解
学数学的妹子总是强的,超过20150001的会得到一个定值就是样例里面那个,小于的直接算就行了。。这题递归爆栈了让我一度以为是手动模拟栈。。感觉很刺激。
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<vector>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<map>
#include<set>
using namespace std;
//thanks to pyf ...
//thanks to qhl ...
#define INF 0x3f3f3f3f
#define CLR(x,y) memset(x,y,sizeof(x))
#define mp(x,y) make_pair(x,y)
typedef pair<int, int> PII;
typedef long long ll;
const int N = 1e6 + 5;
int main()
{
ll n;
int T;
cin >> T;
while (T--)
{
cin >> n;
ll ans;
if (n >= 20150001)
{
ans = 20152014;
}
else
ans = n + 2014;
cout << ans << endl;
}
}
B - 岛屿的数量
这题是结束之后补的。思路和题解差不多,就是比赛的时候想具体实现的时候有点问题。我一开始是想先把连续相同高度合并再用高度直接把山峰盆地处理出来发现有点问题。后来发现大佬用vis标记这个高度旁边的有没有被淹掉。淹掉这个的时候他周围已经全被淹了那么说明淹掉了个山峰sum–,如果淹这个的时候发现周围两个都没被淹那么多出了个山峰sum++,其他情况不变。
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<vector>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<map>
#include<set>
using namespace std;
//thanks to pyf ...
//thanks to qhl ...
#define INF 0x3f3f3f3f
#define CLR(x,y) memset(x,y,sizeof(x))
#define mp(x,y) make_pair(x,y)
typedef pair<int, int> PII;
typedef long long ll;
const int N = 1e6 + 5;
struct Query
{
int h;
int id;
bool operator < (const Query &rhs) const
{
return h < rhs.h;
}
} Q[N];
struct Island
{
int h;
int id;
bool operator < (const Island &rhs) const
{
return h < rhs.h;
}
} a[N];
int ans[N];
int vis[N];
int main()
{
int n, m;
while (cin >> n >> m)
{
for (int i = 1; i <= n; i++)
{
cin >> a[i].h;
a[i].id = i;
}
for (int i = 1 ; i <= m; i++)
{
cin >> Q[i].h;
Q[i].id = i;
}
sort(a + 1, a + 1 + n);
sort(Q + 1, Q + 1 + m);
int sum = 1;
int cur_Island_pos = 1;
CLR(vis, 0);
for (int i = 1; i <= m; i++)
{
while (a[cur_Island_pos].h <= Q[i].h && cur_Island_pos <= n)
{
if (a[cur_Island_pos].id == 1)
{
if (vis[2])
sum --;
}
else if (a[cur_Island_pos].id == n)
{
if (vis[n - 1])
sum--;
}
else
{
if (vis[a[cur_Island_pos].id - 1] && vis[a[cur_Island_pos].id + 1])
sum --;
else if (!vis[a[cur_Island_pos].id - 1] && !vis[a[cur_Island_pos].id + 1])
sum ++;
}
vis[a[cur_Island_pos].id] = 1;
cur_Island_pos ++;
}
ans[Q[i].id] = sum;
}
for (int i = 1 ; i <= m; i++)
cout << ans[i] << endl;
}
}
C - N! Problem
耿直的签到题。。。
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<vector>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<map>
#include<set>
using namespace std;
//thanks to pyf ...
//thanks to qhl ...
#define INF 0x3f3f3f3f
#define CLR(x,y) memset(x,y,sizeof(x))
#define mp(x,y) make_pair(x,y)
typedef pair<int,int> PII;
typedef long long ll;
const int N = 1e6+5;
int main()
{
int n;
while(cin >> n)
{
ll ans = 1;
for(int i =1;i<=n;i++)
ans *= i;
cout << ans << endl;
}
}
D - 青蛙过河
应该算是个递推吧。。dp? 当前位置的最小值是可以转移过来的位置的最小值,然后判断自己这个位置是不是石头,是的话最小值+1
膜一下CSL 嘲讽我不加return 0;然后自己加了之后狂WA
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<vector>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<map>
#include<set>
using namespace std;
//thanks to pyf ...
//thanks to qhl ...
#define INF 0x3f3f3f3f
#define CLR(x,y) memset(x,y,sizeof(x))
#define mp(x,y) make_pair(x,y)
typedef pair<int, int> PII;
typedef long long ll;
const int N = 1e6 + 5;
int a[N];
int vis[N];
int dp[N];
int main()
{
int l, s, t, n;
while (cin >> l >> s >> t >> n)
{
CLR(vis, 0);
CLR(dp, INF);
for (int i = 0; i < n; i++)
{
cin >> a[i];
vis[a[i]] = 1;
}
dp[0] = 0;
vis[0] = 1;
for (int i = 0 ; i < l ; i ++)
{
for (int j = i + s ; j <= i + t; j++)
{
if (j >= l)
dp[l] = min(dp[l], dp[i]);
else if (vis[j])
dp[j] = min(dp[i] + 1, dp[j]);
else dp[j] = min(dp[j], dp[i]);
}
}
// for (int i = 0; i <= l; i++)
// cout << dp[i] << " ";
// cout << endl;
cout << dp[l] << endl;
}
}
E - Vacations
恕我直言这题和后面那题CF都是我以前就做过的。。直接就上代码了。这个题根据我的记忆应该不难,直接决策dp就行了 0,1,2表示不做和做什么然后分情况讨论一下dp式 这种dp还是比较好想的。(菜鸡好像也就只能想想这种dp了。。
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<vector>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<map>
#include<set>
using namespace std;
//thanks to pyf ...
//thanks to qhl ...
#define INF 0x3f3f3f3f
#define CLR(x,y) memset(x,y,sizeof(x))
#define mp(x,y) make_pair(x,y)
typedef pair<int, int> PII;
typedef long long ll;
const int N = 1e6 + 5;
int dp[105][3]; // 0 buzuo 1 gym 2 contest
int day[105];
int main()
{
int n;
while (cin >> n)
{
for (int i = 1; i <= n; i++)
{
cin >> day[i];
}
memset(dp, INF, sizeof(dp));
dp[0][0] = 0;
dp[0][1] = 0;
dp[0][2] = 0;
for (int i = 1; i <= n; i++)
{
dp[i][0] = min(dp[i - 1][0], min(dp[i - 1][1], dp[i - 1][2])) + 1;
if (day[i] == 1)
{
dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]);
}
else if (day[i] == 2)
{
dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]);
}
else if (day[i] == 3)
{
dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]);
dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]);
}
// cout << dp[i][0] <<" " << dp[i][1] <<" " << dp[i][2] << endl;
}
int Min = INF ;
for (int i = 0; i < 3; i++)
Min = min(Min, dp[n][i]);
cout << Min << endl;
}
return 0;
}
F - Present
贪心二分。这里判断的时候用了个小技巧用数组去维护这个序列。。具体忘了略略略。
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<vector>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<map>
using namespace std;
//thanks to pyf ...
#define INF 0x3f3f3f3f
#define CLR(x,y) memset(x,y,sizeof(x))
typedef pair<int,int> PII;
typedef long long ll;
const int N = 1e5+5;
ll a[N];
ll pre_sum[N];
bool judge(ll n,ll m,ll w,ll tar)
{
CLR(pre_sum,0);
for(int i=0;i<n;i++)
{
i!=0 ? pre_sum[i] = pre_sum[i-1] : pre_sum[i] = 0;
ll cur = pre_sum[i];
if(i>=w)
cur -= pre_sum[i-w];
if(cur+a[i]<tar)
{
pre_sum[i] += (tar-cur-a[i]);
}
}
return pre_sum[n-1]<=m;
}
int main()
{
ll n,m,w;
while(cin >> n >> m >> w)
{
ll l = INF,r = 0;
for(int i=0;i<n;i++)
{
cin >> a[i];
l = min(a[i],l);
r = max(a[i],r);
}
r += m;
// r = INF;
// cout << l << " " << r << endl;
ll ans ;
ll mid ;
while(l<=r)
{
mid = (l+r)/2;
// cout << mid << endl;
if(judge(n,m,w,mid))
{
ans = mid;
l = mid+1;
}
else
r = mid-1;
}
cout << ans << endl;
}
return 0;
}
G - treecnt
嗯。。。还没补。。
H - 和为K的组合
我们的口号是 暴搜强无敌
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<vector>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<map>
#include<set>
using namespace std;
//thanks to pyf ...
//thanks to qhl ...
#define INF 0x3f3f3f3f
#define CLR(x,y) memset(x,y,sizeof(x))
#define mp(x,y) make_pair(x,y)
typedef pair<int, int> PII;
typedef long long ll;
const int N = 1e6 + 5;
int a[N];
ll k ;
int n;
int flag = 0;
void dfs(int i, ll sum)
{
if (flag)
return ;
if (i >= n)
{
if (sum == k)
flag = 1;
return;
}
dfs(i + 1, sum);
dfs(i + 1, sum + a[i]);
}
int main()
{
while (cin >> n >> k)
{
flag = 0;
for (int i = 0; i < n; i++)
cin >> a[i];
dfs(0, 0);
if (!flag)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
}
还是菜啊QWQ 菜鸡就要多努力