Codeforces Round #263 (Div. 2)
A. Appleman and Easy Task
题意:给你一个n*n的图案,每一个点是 o 或 * ,问是否每个位置 都有偶数个相邻的 o n<=100
题解:直接模拟即可
代码:
1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<iostream> 7 #include<vector> 8 #include<map> 9 #include<set> 10 #include<queue> 11 #define inf 1000000000 12 #define maxn 500+100 13 #define maxm 500+100 14 #define eps 1e-10 15 #define ll long long 16 #define pa pair<int,int> 17 using namespace std; 18 inline int read() 19 { 20 int x=0,f=1;char ch=getchar(); 21 while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} 22 while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();} 23 return x*f; 24 } 25 int n; 26 char a[maxn][maxn]; 27 const int dx[4]={0,1,-1,0}; 28 const int dy[4]={1,0,0,-1}; 29 bool solve() 30 { 31 n=read(); 32 for(int i=1;i<=n;i++) 33 for (int j=1;j<=n;j++) 34 { 35 char ch=' '; 36 while(ch!='o'&&ch!='x')ch=getchar(); 37 a[i][j]=ch; 38 } 39 for(int i=1;i<=n;i++) 40 for (int j=1;j<=n;j++) 41 { 42 int cnt=0; 43 for (int k=0;k<4;k++) 44 { 45 int x=i+dx[k],y=j+dy[k]; 46 if(x>0&&x<=n&&y<=n&&y>0) 47 if(a[x][y]=='o')cnt++; 48 } 49 if(cnt&1)return 0; 50 } 51 return 1; 52 } 53 int main() 54 { 55 if(solve())puts("YES");else puts("NO"); 56 return 0; 57 }
B. Appleman and Card Game
题意:给你n个字母,你可以从中选出k个,若你选了 i 个 同样的字母 ,你将获得 i*i 的分数 ,求最大分数。 n and k (1 ≤ k ≤ n ≤ 105).
题解:贪心选取即可,从最多的开始 能选就选
代码:
1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<iostream> 7 #include<vector> 8 #include<map> 9 #include<set> 10 #include<queue> 11 #define inf 1000000000 12 #define maxn 500000 13 #define maxm 500+100 14 #define eps 1e-10 15 #define ll long long 16 #define pa pair<int,int> 17 18 using namespace std; 19 inline int read() 20 { 21 int x=0,f=1;char ch=getchar(); 22 while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} 23 while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();} 24 return x*f; 25 } 26 int n,k,a[maxn]; 27 ll ans; 28 bool cmp(int a,int b) 29 { 30 return a>b; 31 } 32 ll sqr(ll x) 33 { 34 return x*x; 35 } 36 int main() 37 { 38 n=read();k=read(); 39 for(int i=1;i<=n;i++) 40 { 41 char ch=' '; 42 while(ch<'A'||ch>'Z')ch=getchar(); 43 a[ch-'A'+1]++; 44 } 45 sort(a+1,a+27,cmp); 46 for(int i=1;i<=26;i++) 47 { 48 ans+=sqr(min(a[i],k)); 49 k-=a[i]; 50 if(k<=0)break; 51 } 52 cout<<ans<<endl; 53 return 0; 54 }
C. Appleman and Toastman
题意:给你n个数,刚开始是一段,每次可以选择一段中的任何节点,将这段分为两段,这两段各自的和将计入到得分里,继续操作,直到分为n段,求最大得分n (1 ≤ n ≤ 3·105).
题解:类似于合并果子==切割木板,只不过这题是求最大花费,则可以把每个值取负,做一遍合并果子,最后输出答案的绝对值即可。
代码:
1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<iostream> 7 #include<vector> 8 #include<map> 9 #include<set> 10 #include<queue> 11 #define inf 1000000000 12 #define maxn 500000+1000 13 #define maxm 500+100 14 #define ll long long 15 using namespace std; 16 inline ll read() 17 { 18 ll x=0,f=1;char ch=getchar(); 19 while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} 20 while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();} 21 return x*f; 22 } 23 int main() 24 { 25 freopen("input.txt","r",stdin); 26 freopen("output.txt","w",stdout); 27 int i,n=read(); 28 priority_queue<ll,vector<ll>,greater<ll> >q; 29 ll ans=0; 30 for(i=1;i<=n;i++) 31 { 32 ll x=read(); 33 q.push(-x); 34 ans+=-x; 35 } 36 for(i=1;i<n;i++) 37 { 38 ll x=q.top();q.pop(); 39 ll y=q.top();q.pop(); 40 q.push(x+y); 41 ans+=x+y; 42 } 43 cout<<-ans<<endl; 44 return 0; 45 }