# T1

T1 智障难度。。。只要会编程应该都会做吧。。。我们就跳过此题

# T2

# include<cstdio>
# include<cstring>
# include<algorithm>
using namespace std;
const int N = 1e3 + 10;
struct node
{
int val,len;
}a[N];
int n,q,i,pre,len,ans;
bool cmp(node a,node b)
{
return a.val < b.val;
}
int getans(int a,int b,int len)
{
int val = 0,sum = 1;
while (len--)
{
val += (a % 10) * sum;
a /= 10;
sum *= 10;
}
if (val == b) return 1;
else return 0;
}
int main()
{
scanf("%d%d",&n,&q);
for (i = 1;i <= n; i++)
{
scanf("%d",&a[i].val);
int tmp = a[i].val; len = 0;
while (tmp)
{
len++;
tmp /= 10;
}
a[i].len = len;
}
sort(a + 1,a + n + 1,cmp);
for (i = 1;i <= q; i++)
{
scanf("%d%d",&len,&pre);
ans = -1;
for (int j = 1;j <= n; j++)
{
if (a[j].len < len) continue;
if (getans(a[j].val,pre,len)) { ans = a[j].val; break; }
}
printf("%d\n",ans);
}
return 0;
}

# T3

# include<cstdio>
# include<cstring>
# include<algorithm>
using namespace std;
const int N = 1e2 + 10;
struct node
{
int x,y,cost,col,p;
}q[N * N * 500];
int a[N][N],bz[N][N][4],dir[4][2] = {{0,1},{1,0},{-1,0},{0,-1}};
int n,m,i,ans;
int main()
{
memset(bz,0x3f,sizeof(bz));
scanf("%d%d",&m,&n);
for (i = 1;i <= n; i++)
{
int x,y,tmp;
scanf("%d%d%d",&x,&y,&tmp);
++tmp;
a[x][y] = tmp;
}
int h = 1,t = 1;
bz[1][1][a[1][1]] = 0;
q[h] = (node){1,1,0,a[1][1],0};
while (h <= t)
{
node now = q[h++];
for (i = 0;i < 4; i++)
{
int x1 = now.x + dir[i][0],y1 = now.y + dir[i][1];
if (x1 < 1 || x1 > m || y1 < 1 || y1 > m) continue;
if (!a[x1][y1] && now.p) continue;
if (a[x1][y1] == now.col)
{
int col = now.col;
int cost = now.cost;
if (cost >= bz[x1][y1][col]) continue;
bz[x1][y1][col] = cost;
q[++t] = (node){x1,y1,cost,col,0};
}else
if (a[x1][y1] != now.col && a[x1][y1] != 0)
{
int col = a[x1][y1];
int cost = now.cost + 1;
if (cost >= bz[x1][y1][col]) continue;
bz[x1][y1][col] = cost;
q[++t] = (node){x1,y1,cost,col,0};
}else
if (a[x1][y1] == 0 && now.p == 0)
{
int col = 1;int cost = now.cost + 2;
if (col != now.col) ++cost;
if (cost < bz[x1][y1][col])  //这里注意不要直接continue，不然下个点不能转移，考场这里打错了。。。
{
bz[x1][y1][col] = cost;
q[++t] = (node){x1,y1,cost,col,1};
}
col++; cost = now.cost + 2;
if (col != now.col) ++cost;
if (cost >= bz[x1][y1][col]) continue;
bz[x1][y1][col] = cost;
q[++t] = (node){x1,y1,cost,col,1};
}
}
}
ans = min(bz[m][m][1],bz[m][m][2]);
if (ans > 2 * m * m) puts("-1");
else printf("%d\n",ans);
return 0;
}

# T4

# include<cstdio>
# include<cstring>
# include<algorithm>
using namespace std;
const int N = 5e5 + 10;
struct node
{
int dis,val;
}a[N];
int f[N],q[N];
int n,k,d,maxx;
bool check(int x,int xia)
{
int h = 1,t = 1,ans = 0,i = 0,fir;
f[0] = q[1] = 0;
for (i = 1;a[i].dis < xia && i <= n; i++)
continue;   //前面有一些格子的距离小于下界，则是无法跳到，直接去除
fir = i;
for (;i <= n; i++)
{
if (a[i].dis - a[i - 1].dis > (x + d)) break; //如果和前面一个格子距离已经大于上界了，则直接break就好了，后面的肯定都不能转移。
while (a[i].dis - a[fir].dis >= xia && fir < i)
{
while (h <= t && f[q[t]] < f[fir]) t--;
q[++t] = fir++;
}
while (h <= t && a[i].dis - a[q[h]].dis > (x + d)) h++;
if (h > t) f[i] = -0x3f3f3f3f;  //当前格子跳不到
else
f[i] = f[q[h]] + a[i].val;
ans = max(ans,f[i]);
}
return ans >= k;
}
int main()
{
scanf("%d%d%d",&n,&d,&k);
for (int i = 1;i <= n; i++)
scanf("%d%d",&a[i].dis,&a[i].val);
int l = 0,r = a[n].dis,ret = 0;
while (l <= r)
{
int mid = (l + r) >> 1;
if (check(mid,max(d - mid,1))) r = mid - 1,ret = mid;
else l = mid + 1;
}
if (check(ret,max(d - ret,1))) printf("%d\n",ret);
else puts("-1");
return 0;
}