先放课程表:
调和数列问题(math.cpp/math.in/math.out):
1.00
3.71
0.04
5.19
0.00
3 card(s)
61 card(s)
1 card(s)
273 card(s)
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
long double sum,x;
int n;
int main(){
freopen("math.in","r",stdin);
freopen("math.out","w",stdout);
while (1){
x=0.000;
scanf("%llf",&x);
if (fabs(x)<0.000001) return 0;
n=1;
sum=0.000;
while (sum<x){
n++;
sum+=1.0/n;
}
cout <<n-1<<" card(s)"<<endl;
}
fclose(stdin);
fclose(stdout);
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int solve(double x) {
double t = 0;
for (int i = 2; ; i++) {
t += 1.0 / i;
if (t >= x) return i - 1;
}
return -1;
}
int main() {
double x;
freopen("math.in", "r", stdin);
freopen("math.out", "w", stdout);
while (cin >> x, x != 0)
cout << solve(x) << " card(s)" << endl;
fclose(stdin);
fclose(stdout);
return 0;
}
数字环打印(circle.cpp/circle.in/circle.out):
20 2
输入样例2:
10 3
20 23
21 22
输出样例2:
10 17 16
11 15
12 13 14
for (i=1;i<=s-1;i++)
,但是当S=1时,是不会填数的。#include <iostream>
#include <cstdio>
using namespace std;
int ans[105][105],s,n,cnt;
int main(){
freopen("circle.in","r",stdin);
freopen("circle.out","w",stdout);
scanf("%d%d",&s,&n);//s和n写反了,不要在意这些细节
cnt=s;
if (n==1) ans[1][1]=s;
for (int i=1;i<n;i++)
ans[i][1]=cnt++;
for (int i=1;i<n;i++)
ans[n][i]=cnt++;
for (int i=n;i>1;i--)
ans[i][n]=cnt++;
for (int i=n;i>1;i--)
ans[1][i]=cnt++;
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
if (!ans[i][j]) cout <<" "<<" ";
else if (j==n) cout <<ans[i][j]<<endl;
else cout <<ans[i][j]<<" ";
fclose(stdin);
fclose(stdout);
return 0;
}
序列(seq.cpp/seq.in/seq.out):
4
4 5 1
6 10 3
7 10 3
5 6 1
4
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 10;
struct rec {
int l, r, c;
};
bool cmp(const rec &a, const rec &b) {
return a.r < b.r;
}
int n, flag[MAXN];
rec a[MAXN];
int main() {
freopen("seq.in", "r", stdin);
freopen("seq.out", "w", stdout);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i].l >> a[i].r >> a[i].c;
sort(a + 1, a + n + 1, cmp);
for (int i = 1; i <= n; i++) {
for (int j = a[i].l; j <= a[i].r; j++)
a[i].c -= flag[j];
if (a[i].c <= 0) continue;
for (int j = a[i].r; a[i].c > 0; j--)
if (!flag[j])
flag[j] = 1, a[i].c--;
}
int ans = 0;
for (int i = 0; i <= a[n].r; i++)
ans += flag[i];
cout << ans << endl;
fclose(stdin);
fclose(stdout);
return 0;
}
信息(msg.cpp/msg.in/msg.out):
5
2 4 2 3 1
3
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
int n, a[MAXN], num[MAXN], vis[MAXN], cnt, ans = 1 << 30;
void dfs(int x, int dep) {
vis[x] = cnt;
num[x] = dep;
if (vis[a[x]] > 0) {
if (vis[x] == vis[a[x]])
ans = min(ans, num[x] - num[a[x]] + 1);
} else
dfs(a[x], dep + 1);
}
int main() {
freopen("msg.in", "r", stdin);
freopen("msg.out", "w", stdout);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
cnt = 1;
for (int i = 1; i <= n; i++)
if (!vis[i]) dfs(i, 1), cnt++;
cout << ans << endl;
return 0;
}
#include <iostream>
#include <cstdio>
using namespace std;
int n,f[200005],dis[200005],Min=999999999,last,t;
int find(int now){
if (f[now]!=now){
int last=f[now];
f[now]=find(f[now]);
dis[now]+=dis[last];
}
return f[now];
}
void check(int a,int b){
int x=find(a),y=find(b);
if (x!=y){
f[x]=y;
dis[a]=dis[b]+1;
}
else Min=min(Min,dis[a]+dis[b]+1);
return;
}
int main(){
freopen("msg.in","r",stdin);
freopen("msg.out","w",stdout);
cin >>n;
for (int i=1;i<=n;i++) f[i]=i;
for (int i=1;i<=n;i++){
cin >>t;
check(i,t);
}
cout <<Min;
fclose(stdin);
fclose(stdout);
return 0;
}
emming,我真是太菜了,连普通的模拟题都WA了40分。昨天的贪心是不太容易看出来的贪心,我已经想到要排序(不过我觉得排序没用就没排),标记一个数字的重要程度,但是离正解还是有点差距的。拿了30分,比爆搜少了10分QAQ。看来我哪个部分都要加强......
相关概念:
作用:
#include <bits/stdc++.h>
#define INF 999999999
using namespace std;
int dui[1000005],n,t,cnt,x;
void up(int k){
if (k==1) return;
if (dui[k]<dui[k>>1]){
swap(dui[k],dui[k>>1]);
up(k>>1);
}
return;
}
void down(int k){
int p=2*k;
if (2*k>cnt) return;
if (dui[p]>dui[p+1]) p++;
if (dui[k]>dui[p]){
swap(dui[k],dui[p]);
down(p);
}
return;
}
inline void Input (){
cnt++;
dui[cnt]=x;
up(cnt);
return;
}
inline void out(){
dui[1]=dui[cnt];
dui[cnt]=INF;
cnt--;
down(1);
return;
}
int main(){
for (int i=1;i<=1000005;i++)
dui[i]=INF;
scanf("%d",&n);
for (int i=1;i<=n;i++){
scanf("%d",&t);
if (t==1){
scanf("%d",&x);
Input();
}
if (t==2){
printf("%d\n",dui[1]);
}
if (t==3){
out();
}
}
return 0;
}
支持:维护一个元素不重复的集合
性质:对于树中的任意节点$v$,都要满足:
struct node { // 描述二叉树的一个结点
int f, l, r; //父节点、左子节点、右子节点
};
node tree[MAXN];
然后在使用一个变量储存根节点的下标。
今天考搜索,虽然说不是很难但是还是很容易错,很耗时间的(我NOIP2018$T3$就打了一个半小时然后才拿5分QAQ)。现在最重要的是勤练习,我终于凑够3$k$字了,哈哈哈哈哈哈。
本文作者:Snowflake_Pink
本文链接:https://snowflake.pink/archives/9/
最后修改时间:2020-04-13 11:09:20
本站未注明转载的文章均为原创,并采用 CC BY-NC-SA 4.0 授权协议,转载请注明来源,谢谢!