全是天梯赛原题,因为最近练的多,做的如鱼得水。但是这种简单题做多了会产生自己很强的错觉,不能再刷了,明天做区域赛的题换换脑子,还能打击一波自己。一共有9分小分没拿到,L3-3连样例都过不了。
L1-3 阅览室
题目
没考虑到借书还书之后可以再借,wa了一个点。
代码:
#include<bits/stdc++.h>
using namespace std;
const int N = 1002;
#define mem(a,x) memset(a,x,sizeof(a))
#define fir(i,a,b) for(int i=a;i<=b;++i)
typedef long long ll;
typedef pair<int,int> PII;
int n,m,k,T;
int st[N];
int ed[N];
PII jilu[N];
int fun(int a,int b)
{
return 60*a + b;
}
void solve()
{
// ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
scanf("%d",&n);
int now = 0;
while(now < n)
{
mem(st,-1); mem(ed,-1);
for(int i=1;i<=1000;++i) jilu[i].first = jilu[i].second = 0;
int id; char ch; int h,mm;
int cnt = 0;
int ans = 0;
while(scanf("%d %c %d:%d",&id,&ch,&h,&mm)!=EOF)
{
if(id == 0)
{
if(cnt == 0)
{
printf("0 0\n");
}
else
{
double res = 1.0*ans/cnt;
ans = round(res);
// if(res-1.0*ans>=0.5) ans++;
printf("%d %d\n",cnt,ans);
}
break;
}
else
{
if(ch == 'S')
{
st[id] = fun(h,mm);
}
else
{
ed[id] = fun(h,mm);
if(st[id] != -1)
{
cnt++;
ans += max( ed[id] - st[id],0);
st[id] = -1; ed[id] = -1;
}
}
}
}
now++;
}
}
signed main(void)
{
solve();
return 0;
}
L1-6整除光棍
题目
题意: 给定不以5为结尾的奇数x,保证有一个长度为cnt的1111111可以整除x。求最小的11111,使得能够整除。
思路: 模拟除法,先处理出一个比x大的1111。然后用它除以x得到商,再模一下得到余数,余数补1,直到余数为0,商就是答案,长度cnt也可以自然得到。(赛时手敲快读快写开int128,wa了3分。经典骗分)
时间复杂度: O(能过)
代码:
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
typedef long long ll;
typedef pair<int,int> PII;
int n,m,k,T;
int x;
void solve()
{
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>x;
int ans = 1;
int cnt = 1;
while(ans < x)
{
ans = ans * 10 + 1;
cnt++;
}
while(true)
{
printf("%d",ans/x);
ans %= x;
if(ans == 0) break;
ans = ans * 10 + 1;
++cnt;
}
printf(" %d",cnt);
}
signed main(void)
{
solve();
return 0;
}
题目
题意: 给定一个链表,让你重排,1->2->3…->n.变成1->n->2->n-1…
思路: 这题以前就不太明白,有点心虚,乱写了一个。就直接桶排序,或者叫静态链表,然后从起点遍历到链表尾,然后两个指针维护乱输出就行了。
(坑点:有可能有冗余节点,就是不在以head为头指针的链表中,所以不能用给定的n,要用迭代得到的对应链表的节点个数,扣我3分,感觉好离谱)
时间复杂度: O(n)
代码:
#include<bits/stdc++.h>
using namespace std;
const int N = 2e6+10;
#define mem(a,x) memset(a,x,sizeof(a))
#define fir(i,a,b) for(int i=a;i<=b;++i)
typedef long long ll;
typedef pair<int,int> PII;
#define int long long
int n,m,k,T;
struct node{
int add;
int data;
int ne;
}vv[N],a[N];
vector<int> va[N];
int to[N]; //i这个数排第几
int root;
int tot = 0;
void dfs(int cur)
{
if(cur == -1) return ;
int j = va[cur][0];
++tot;
a[tot].add = vv[cur].add;
a[tot].data = vv[cur].data;
a[tot].ne = vv[cur].ne;
dfs(j);
}
void solve()
{
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>root>>n;
for(int i=1;i<=n;++i)
{
int add,data,ne;
cin>>add>>data>>ne;
vv[add].add = add;
vv[add].data = data;
vv[add].ne = ne;
va[add].push_back(ne);
}
dfs(root);
// for(int i=1;i<=tot;++i)
// {
// cout<<i<<":"<<a[i].add<<endl;
// }
int i=1,j=tot;
int cnt = 0;
while(cnt < tot)
{
if(cnt & 1)
{
if(cnt == tot-1) printf("%05d %d -1",a[i].add,a[i].data);
else printf("%05d %d %05d\n",a[i].add,a[i].data,a[j].add);
++i;
}
else
{
if(cnt == tot-1) printf("%05d %d -1",a[j].add,a[j].data);
else printf("%05d %d %05d\n",a[j].add,a[j].data,a[i].add);
j--;
}
cnt++;
}
}
signed main(void)
{
solve();
return 0;
}
/*
00100 5
00000 4 68237
00100 1 12309
68237 6 -1
33218 3 00000
12309 2 33218
00100 3
00000 3 -1
00100 2 00010
00010 5 00000
*/
倒数第二题的贪心+线段树做过原题,结果还楞想了半天才想起来。平时做题的深度不太够,浮于表面,还得沉下心好好练题啊。