思路:每次读入一个字符,读到'.'就输出"xixixixi."
注意:不能用string直接读如,因为输入包含空格,或者可以用getlin(cin,s)读入一整行
#include<bits/stdc++.h>
#define endl '\n'
//#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 2e5+10;
int n, m, k;
void sovle(){
char ch;
while(scanf("%c",&ch)!=EOF){
cout<<ch;
if(ch=='.'){
cout<<"xixixixi.";
}
}
}
int main()
{
//ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int t = 1;
//cin>>t;
while (t --){
sovle();
}
return 0;
}
思路:数据范围很小,可以二进制枚举暖源,然后判断每种方案的所有小鸡是否都满足温暖值
#include<bits/stdc++.h>
#define endl '\n'
//#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 1e6+10;
int n, b, k[25],m[25],res=INT_MAX;
void sovle(){
cin>>n>>b;
vector<PII>e(b); //储存灯的左右边界
int a[105]; //储存小鸡的孵化温度
int w[15]; //储存灯的花费
memset(a,0,sizeof(a));
memset(w,0,sizeof(w));
for(int i=0;i<n;i++){
int l,r,x; //左边界l和右边界r,孵化温度x
cin>>l>>r>>x;
for(int j=l;j<=r;j++){
a[j]=x; //令l到r的a[j]的孵化温度为x
}
}
for(int i=0;i<b;i++){
cin>>e[i].first>>e[i].second>>k[i]>>m[i]; //输入灯的左右边界与温度与花费
}
for(int i=0;i<(1<<b);i++){
vector<int>h(105); //储存选中的灯
int ans=0; //当前方案的花费
for(int j=0;j<b;j++){
if((i>>j)&1){ //若选中
ans+=m[j];
for(int l=e[j].first;l<=e[j].second;l++){
h[l]+=k[j]; //计算选中的灯加热区间的温度
}
}
}
int ok=1;
for(int j=1;j<=100;j++){
if(a[j]!=0&&a[j]>h[j]){ //若加热的温度低于孵化温度
ok=0;
break;
}
}
if(ok){
res=min(res,ans); //若满足,取最小花费
}
}
cout<<res;
}
int main()
{
//ios::sync_with_stdio(false), cin.tie(0),cout.tie(0);
int t = 1;
//cin>>t;
while (t --){
sovle();
}
return 0;
}
思路:与B题类似,这一题也可以用二进制枚举土豆,然后判断所选土豆构成的矩形里面有没有未选中的土豆,若无则方案数加一。
#include<bits/stdc++.h>
#define endl '\n'
//#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 2e5+10;
int n, k;
void sovle(){
cin>>n;
vector<PII>v(n); //储存点的位置
int m=0; //方案数
for(int i=0;i<n;++i){
cin>>v[i].first>>v[i].second; //输入点的位置
}
for(int i=0;i<(1<<n);++i){
vector<PII>q; //储存选中的点
int max_x=0,max_y=0,min_x=INT_MAX,min_y=INT_MAX; //矩形的边界
for(int j=0;j<n;j++){
if((i>>j)&1){ //若选中
max_x=max(max_x,v[i].first); //下边界
max_y=max(max_y,v[i].second); //右边界
min_x=min(min_x,v[i].first); //上边界
min_y=min(min_y,v[i].second); //左边界
}
else {
q.push_back(v[j]); //放入未选中的点
}
}
int ok=1;
for(auto [ x , y ]:q ){
if (x >= min_x && x <= max_x && y >= min_y && y <= max_y) { //若未选中的点在矩形内
ok = 0;
break;
}
}
if(ok){ //若矩形内只有选中的点
m++;
}
}
cout<<m;
}
int main()
{
//ios::sync_with_stdio(false), cin.tie(0),cout.tie(0);
int t = 1;
//cin>>t;
while (t --){
sovle();
}
return 0;
}
思路:暴力,操作三种方案各操作一次,取最小值即可。
#include<bits/stdc++.h>
#define endl '\n'
//#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 2e5+10;
ll n, m, k,max1;
int a[2005];
ll ff1(int n,int a[]){
int j=1,b=n,num=0;
while(b<=n){
num+=(a[j]+a[b])%3;
j+=2;
b+=2;
}
return num;
}
ll ff2(int n,int a[]){
int j=n-1,b=n,num=0;
while(j>=1){
num+=(a[j]+a[b])%3;
j-=2;
b-=2;
}
return num;
}
ll ff3(int n,int a[]){
int j=1,b=n,num=0;
while(b>j){
num+=(a[j]+a[b])%3;
j++;
b--;
}
return num;
}
void sovle(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
max1=max(ff1(n,a),max1);
max1=max(ff2(n,a),max1);
max1=max(ff3(n,a),max1);
cout<<max1;
}
int main()
{
ios::sync_with_stdio(false), cin.tie(0),cout.tie(0);
int t = 1;
//cin>>t;
while (t --){
sovle();
}
return 0;
}
思路:
#include<bits/stdc++.h>
#define endl '\n'
//#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 2e5+10;
int n, m, sum,cnt,a[10000005];
bool s[10000005];
void prime(int n){ //寻找100005内的素数
for(int i=2;i<=n;++i){
if(!s[i]){ //若不是合数
a[cnt++]=i; //标记为素数
}
for(int j=0;i*a[j]<=n;++j){ //欧拉筛,筛选素数
s[i*a[j]]=1;
if(i%a[j]==0){
break;
}
}
}
}
void solve(){
cin>>n;
vector<int>v;
for(int i=0;a[i]*a[i]<=n&&i<cnt;++i){ //寻找因数
int qw=0; //记录该因数贡献的次方
while(n%a[i]==0){ //一直到不能整除
qw++;
n/=a[i]; //每次被除数都要变化
}
if(qw){
v.push_back(qw); //存入因数
}
}
if(n>1){
v.push_back(1); //若被除数不能被整除到1,必然有一个大于sqrt(x)的因数
}
int sum=1;
while(!v.empty()){
sum*=(v.back()+1); //因为该因数可能有0个的情况所以要加一
v.pop_back();
}
cout<<sum<<endl;
}
int main()
{
ios::sync_with_stdio(false), cin.tie(0),cout.tie(0);
int t;
cin>>t;
prime(100005);
while (t --){
solve();
}
return 0;
}
思路:贪心,每次都减去最大的那个整数。当n=10时两次即可完成。
#include<bits/stdc++.h>
#define endl '\n'
//#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 2e5+10;
ll n, m, k,sum;
void sovle(){
ll max=0;
cin>>n;
while(n){
sum++;
m=n;
for(int i=0;m!=0;++i){
k=m%10;
if(k>max){
max=k;
}
m/=10;
}
n-=max;
if(n<10){
break;
}
if(n==10){
sum+=2;
break;
}
max=0;
}
cout<<sum;
return;
}
int main()
{
ios::sync_with_stdio(false), cin.tie(0),cout.tie(0);
int t = 1;
//cin>>t;
while (t --){
sovle();
}
return 0;
}
思路:判断看完视频后剩余的时间是否大于等于加纳出现的时间
#include<bits/stdc++.h>
#define endl '\n'
//#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 2e5+10;
ll n, m, k,sum;
void sovle(){
cin>>n>>m>>k;
sum+=k/n;
if(k%n>=m){
sum++;
}
cout<<sum;
}
int main()
{
ios::sync_with_stdio(false), cin.tie(0),cout.tie(0);
int t = 1;
//cin>>t;
while (t --){
sovle();
}
return 0;
}