https://www.nowcoder.com/acm/contest/64#question
都是比较水的题,不写思路了,直接放代码。
A.星图
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
using namespace std;
int l[1010][1010],u[1010][1010];
int b[1010][1010];
char a[1010][1010];
int main()
{
int n,m,q;
int x,y;
char ch[10];
scanf("%d%d%d",&n,&m,&q);
for(int i=1;i<=n;i++)
scanf("%s",a[i]+1);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
if(a[i][j]=='#') b[i][j]=1;
else b[i][j]=0;
}
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
l[i][j+1]=l[i][j]+b[i][j]+b[i][j+1];
u[i+1][j]=u[i][j]+b[i][j]+b[i+1][j];
}
while(q--)
{
scanf("%d%d%s",&x,&y,&ch[0]);
if(ch[0]=='L')
{
if(l[x][y]==0) puts("YES");
else puts("NO");
}
else if(ch[0]=='R')
{
if(l[x][m]-l[x][y]==0) puts("YES");
else puts("NO");
}
else if(ch[0]=='U')
{
if(u[x][y]==0) puts("YES");
else puts("NO");
}
else if(ch[0]=='D')
{
if(u[n][y]-u[x][y]==0) puts("YES");
else puts("NO");
}
}
}
B.好数
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
long long n,l,key1,key2;
char a[1000000];
scanf("%s",a);
l=strlen(a)-1;
while(l>0)
{
if(a[l]!=a[l-1]||a[l]>57||a[l]<48)
{
printf("NO");
exit(0);
}
l--;
}
printf("YES");
}
C.装进肚子
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
/*bool cmp(int x,int y)
{
if(x>y) return true;
else return false;
}*/
struct node
{
int num;
int data;
}c[100000+10];
bool cmp(const node &x, const node &y)
{
return x.data>y.data;//从小到大排<,若要从大到小排则>
}
int main()
{
int n,k;
int a[100000+10],b[100000+10];
ll sum=0;
cin>>n>>k;
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) cin>>b[i];
for(int i=0;i<n;i++) c[i].num=i;
for(int i=0;i<n;i++) c[i].data=a[i]-b[i];
sort(c+0,c+n,cmp);
for(int i=0;i<k;i++) sum+=a[c[i].num];
for(int i=k;i<n;i++) sum+=b[c[i].num];
cout<<sum<<endl;
}
D.ZZZZone爱吃糖
#include <bits/stdc++.h>
using namespace std;
int s[10010];
int main()
{
int n, x, q, y;
long long ans = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
s[i] = s[i - 1] + x;
}
scanf("%d", &q);
while (q--) {
scanf("%d%d", &x, &y);
if (x > y) swap(x, y);
int tmp = s[y] - s[x - 1];
if (tmp > 0) ans += tmp;
}
printf("%lld\n", ans);
}
E.开心的涂刷
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
#define mod 1000000007
ll pow_mod (ll a,ll b){
ll ans=1,base=a;
a%=mod;
while (b!=0)
{
if (b&1==1)//末位为1(否则为0)
ans=(ans*base)%mod;
base=(base*base)%mod;
b>>=1;
}
return ans%=mod;
}
int main()
{
ll n,m,ans;
cin>>n>>m;
m%=mod;
ans=pow_mod(m,n)-(m*pow_mod(m-1,n-1))%mod;
cout<<(ans+mod)%mod<<endl;
}
F.兼职数靶
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
using namespace std;
int main()
{
int n;
char a[13][13];
float sum,avg;
while(~scanf("%d",&n)&&n!=0)
{
sum=0;
for(int i=0;i<13;i++)
{
for(int j=0;j<13;j++)
{
cin>>a[i][j];
if(a[i][j]=='#')
{
if(i==0||i==12||j==0||j==12)
sum+=1;
else if(i==1||i==2||i==10||i==11||j==1||j==2||j==10||j==11)
sum+=2;
else if(i==3||i==4||i==8||i==9||j==3||j==4||j==8||j==9)
sum+=3;
else sum+=4;
}
}
}
avg=sum/n;
printf("%.2f\n",avg);
}
}
G.卡牌游戏
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define Jin 1;
#define Mu 2;
#define Shui 3;
#define Huo 4;
#define Tu 5;
int main()
{
char a[10]="Jin",b[10]="Mu",c[10]="Shui",d[10]="Huo",e[10]="Tu",k1[10],k2[10];
int x,y;
int n;
int g1=0,g2=0;
scanf("%d",&n);
while(n--)
{
scanf("%s%s",k1,k2);
if(strcmp(a,k1)==0) x=1;
if(strcmp(b,k1)==0) x=2;
if(strcmp(c,k1)==0) x=3;
if(strcmp(d,k1)==0) x=4;
if(strcmp(e,k1)==0) x=5;
if(strcmp(a,k2)==0) y=1;
if(strcmp(b,k2)==0) y=2;
if(strcmp(c,k2)==0) y=3;
if(strcmp(d,k2)==0) y=4;
if(strcmp(e,k2)==0) y=5;
if(x==1&&y==2) g1+=3;
if(x==2&&y==1) g2+=3;
if(x==2&&y==5) g1+=3;
if(x==5&&y==2) g2+=3;
if(x==5&&y==3) g1+=3;
if(x==3&&y==5) g2+=3;
if(x==3&&y==4) g1+=3;
if(x==4&&y==3) g2+=3;
if(x==4&&y==1) g1+=3;
if(x==1&&y==4) g2+=3;
}
if(g1>g2) printf("Alice\n");
else if(g1<g2) printf("Bob\n");
else printf("Draw\n");
}
H.Hungry!
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int n;
while(~scanf("%d",&n))
{
while(n--)
printf("gu...");
printf("\nThe story is so boring. And I am so hungry!\n");
}
}
I.快饿死的XzzF
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
int dp[25];
using namespace std;
int main(){
int n;
while(cin>>n){
dp[1]=2;
dp[0]=1;
for(int i=2;i<=n;i++){
dp[i]=dp[i-1]+dp[i-2];
}
cout<<dp[n]<<endl;
}
return 0;
}
J.小猪佩奇练打字
#include <bits/stdc++.h>
using namespace std;
char a[100010], b[10], c[10];
int d[40];
int main()
{
int n;
scanf("%s%d", a, &n);
int m = strlen(a);
for (int i = 0; i < 26; i++) d[i] = i;
for (int i = 0; i < n; i++) {
scanf("%s%s", b, c);
swap(d[b[0] - 'a'], d[c[0] - 'a']);
}
for (int i = 0; i < m; i++) {
printf("%c", d[a[i] - 'a'] + 'a');
}
puts("");
}
K.免费WiFi
#include <bits/stdc++.h>
using namespace std;
int d[5050];
int main()
{
int n, m, ans = 0, x, y;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d%d", &x, &y);
for (int j = x; j <= y; j++) {
d[j]++;
}
}
for (int i = 1; i <= 5000; i++) {
ans = max(ans, (d[i] + m - 1) / m);
}
printf("%d\n", ans);
}