A 分糖果
做一个简单的取模,然后取min
即可
#include <bits/stdc++.h>
using namespace std;
int n , l , r ;
int main()
{
cin >> n >> l >> r;
r -= l/n*n , l %= n;
cout << min( n - 1 , r ) << endl;
}
B方格取数
裸暴力的20分为什么没有人写???
#include<bits/stdc++.h>
using namespace std;
const int dx[] = { 0 , 1 , -1 } , dy[] = { 1 , 0 , 0 };
const int N = 1e3+5;
int n , m , a[N][N] , ans = - 1e9;
bool vis[N][N];
inline int read()
{
int x = 0 , f = 1 , ch = getchar();
while( ( ch < '0' || ch > '9' ) && ch != '-' ) ch = getchar();
if( ch == '-' ) f = -1 , ch = getchar();
while( ch >= '0' && ch <= '9' ) x = ( x << 3 ) + ( x << 1 ) + ch - '0' , ch = getchar();
return x * f;
}
inline void dfs( int x , int y , int sum )
{
if( x == n && y == m )
{
ans = max( ans , sum );
return ;
}
for( int i = 0 , fx , fy ; i < 3; i ++ )
{
fx = x + dx[i] , fy = y + dy[i];
if( fx < 1 || fx > n || fy < 1 || fy > m || vis[fx][fy] ) continue;
vis[fx][fy] = 1 ;
dfs( fx , fy , sum + a[fx][fy] );
vis[fx][fy] = 0;
}
return ;
}
int main()
{
n = read() , m = read();
for( int i = 1 ; i <= n ; i ++ )
for( int j = 1 ; j <= m ; j ++ ) a[i][j] = read();
vis[1][1] = 1 ;
dfs( 1 , 1 , a[1][1] );
cout << ans << endl;
return 0;
}
正解就是DP,但是可以写成记忆化搜索,f[i][j][0]
表示从上面过来,f[i][j][0]
表从从下面过来
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const LL INF = -1e18;
int n, m;
LL w[1005][1005], f[1005][1005][2];
inline LL dfs(int x, int y, int from)
{
if (x < 1 || x > n || y < 1 || y > m) return INF;
if (f[x][y][from] != INF ) return f[x][y][from];
if (from == 0) f[x][y][from] = max(dfs( x+1 , y , 0 ) , max ( dfs( x , y-1 , 0), dfs( x , y-1 , 1 ) ) ) + w[x][y];
else f[x][y][from] = max ( dfs( x-1 , y , 1) , max ( dfs( x , y-1 , 0), dfs( x, y-1, 1) ) ) + w[x][y];
return f[x][y][from];
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j) cin >> w[i][j] , f[i][j][0] = f[i][j][1] = INF;
f[1][1][0] = f[1][1][1] = w[1][1];
cout << dfs(n, m, 1) << endl;
return 0;
}
C 直播获奖
直接用桶排序,统计分数线即可
#include<bits/stdc++.h>
using namespace std;
int t[605];
int n,w;
int main()
{
int x;
cin>>n>>w;
for(int i=1;i<=n;i++)
{
cin>>x;
t[x]++;
int sum=0;
for(int j = 600 ; j >= 0 ; j -- )
{
sum+=t[j];
if(sum >= max( 1 , i * w / 100 ) )
{
printf( "%d " , j );
break;
}
}
}
return 0;
}
D 数字游戏
为什么不用bitset
#include<bits/stdc++.h>
using namespace std;
bitset<8> s;
int main()
{
cin >> s;
cout << s.count() << endl;
}
E 小凯的疑惑
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long a , b;
cin >> a >> b;
cout << a * b - a - b << endl;
}
F 奶酪
枚举两个点,如果距离小于2r
就把两个点用并查集连起来
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 1005;
LL t,n,h,r,father[N] = {};
LL sa[N] = {}, sb[N] = {};
struct node
{
LL x,y,z;
}ball[N] = {};
inline LL read()
{
register LL x = 0,f = 1;
register char ch = getchar();
while(ch < '0' || ch > '9')
{
if(ch == '-') f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9')
{
x = (x<<3)+(x<<1) + ch-'0';
ch = getchar();
}
return x*f;
}
inline LL getfather(int x)
{
if(x == father[x]) return x;
return father[x] = getfather(father[x]);
}
inline LL dis(int a,int b)
{
return (ball[a].x-ball[b].x)*(ball[a].x-ball[b].x) + (ball[a].y-ball[b].y)*(ball[a].y-ball[b].y) + (ball[a].z-ball[b].z)*(ball[a].z-ball[b].z);
}
inline void work()
{
sa[0] = sb[0] = 0;
n = read(); h = read(); r = read();
for(register int i = 1;i <= n;i++)
{
father[i] = i;
ball[i].x = read(); ball[i].y = read(); ball[i].z = read();
if(ball[i].z-r <= 0) sa[++sa[0]] = i;
if(ball[i].z+r >= h) sb[++sb[0]] = i;
}
for(register int i = 1;i < n;i++)
{
for(register int j = i+1;j <= n;j++)
{
if(dis(i,j) > 4*r*r) continue;
father[getfather(i)] = getfather(j);
}
}
for(register int i = 1;i <= sa[0];i++)
{
for(register int j = 1;j <= sb[0];j++)
{
if(getfather(sa[i]) == getfather(sb[j]))
{
puts("Yes");
return ;
}
}
}
puts("No");
return ;
}
int main()
{
t = read();
while(t--) work();
return 0;
}
G RESETO
#include <bits/stdc++.h>
using namespace std;
int n , k , w = 0;
bool s[1005];
int main()
{
cin>>n>>k;
memset(s,1,sizeof(s));
for(int i=2;i<=n;i++)
{
if(s[i])
{
for(int j=i;j<=n;j+=i)
{
if(s[j])
{
w++ , s[j] = 0;
if(w==k) cout<<j , exit(0);
}
}
}
}
}