CodeForces 400
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:
There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X" or "O". Then the player chooses two positive integers a and b(a·b = 12), after that he makes a table of size a × b from the cards he put on the table as follows: the first b cards form the first row of the table, the second b cards form the second row of the table and so on, the last b cards form the last (number a) row of the table. The player wins if some column of the table contain characters "X" on all cards. Otherwise, the player loses.
Inna has already put 12 cards on the table in a row. But unfortunately, she doesn't know what numbers a and b to choose. Help her win the game: print to her all the possible ways of numbers a, b that she can choose and win.
Input
The first line of the input contains integer t(1 ≤ t ≤ 100). This value shows the number of sets of test data in the input. Next follows the description of each of the t tests on a separate line.
The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The i-th character of the string shows the character that is written on the i-th card from the start.
Output
For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair a, b. Next, print on this line the pairs in the format axb. Print the pairs in the order of increasing first parameter (a). Separate the pairs in the line by whitespaces.
Sample Input
4 OXXXOXOOXOOX OXOXOXOXOXOX XXXXXXXXXXXX OOOOOOOOOOOO
3 1x12 2x6 4x3 4 1x12 2x6 3x4 6x2 6 1x12 2x6 3x4 4x3 6x2 12x1 0
题意:给出12张卡片,选择ab使得a*b=12,则把卡片依次分成a行,每行b个,如果某些列全是'X',则win,求得win的方案。
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
#define ll long long
#define MOD 100000
#define N 110
#define M 4 int ans;
int res[];
char s[];
int x[]={,,,,,}; int main()
{
int T;
int i,j,k;
scanf("%d",&T);
while(T--)
{
ans=;
scanf("%s",s);
for(i=;i<;i++)
{
int a=x[i];
int b=/x[i];
int flag=;
for(k=;k<b;k++)
{
for(j=;j<a;j++)
{
if(s[k+j*b]!='X') break;
}
if(j==a)
{
flag=;
break;
}
}
if(flag)
res[++ans]=x[i];
}
printf("%d",ans);
for(int i=;i<=ans;i++) printf(" %dx%d",res[i],/res[i]);
printf("\n");
}
return ;
}
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size n × m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player should choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start tosimultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs:
- some dwarf in one of the chosen lines is located in the rightmost cell of his row;
- some dwarf in the chosen lines is located in the cell with the candy.
The point of the game is to transport all the dwarves to the candy cells.
Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game.
Input
The first line of the input contains two integers n and m(1 ≤ n ≤ 1000; 2 ≤ m ≤ 1000).
Next n lines each contain m characters — the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S".
Output
In a single line print a single integer — either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
Sample Input
3 4 *G*S G**S *G*S
2
1 3 S*G
-1
题意:有一个n*m的矩阵,其中*代表该格是空的,G代表该格有一个小矮人,S代表该格有一个糖果。每次都要选中所有有小矮人还没到达糖果格的那行,选中的这些行的小矮人都要向右走,如果有一行碰到这两种情况之一,所有行的小矮人都要停止向右运动,两种情况是:小矮人遇到糖果就停止运动,小矮人走到最右边了也停止运动。求最少执行多少次才能让所有的小矮人都能到达糖果格子,如果不能完成输出-1。
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
#define ll long long
#define INF 0x3fffffff
#define N 1010 int n,m;
int ans;
int flag;
int now[N];
bool vis[N];
char mpt[N][N]; int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
flag=;
for(int i=;i<=n;i++)
{
scanf("%s",mpt[i]+);
for(int j=;j<=m;j++)
{
if(mpt[i][j]=='G')
{
now[i]=j;
break;
}
else if(mpt[i][j]=='S')
{
flag=;
break;
}
}
}
if(!flag)
{
printf("-1");
continue;
}
ans=;
memset(vis,,sizeof(vis));
while()
{
int Min=INF;
for(int i=;i<=n;i++)
{
if(vis[i]) continue;
for(int j=now[i];j<=m;j++)
{
if(mpt[i][j]=='S' || j==m)
{
Min=min(Min,j-now[i]);
break;
}
}
}
if(Min==INF) break;
ans++;
for(int i=;i<=n;i++)
{
now[i]+=Min;
if(mpt[i][now[i]]=='S' || now[i]==m) vis[i]=;
}
}
printf("%d\n",ans);
}
return ;
}
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns — from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk).
The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like.
Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made!
Input
The first line of the input contains fix integers n, m, x, y, z, p(1 ≤ n, m ≤ 109; 0 ≤ x, y, z ≤ 109; 1 ≤ p ≤ 105).
Each of the following p lines contains two integers xk, yk(1 ≤ xk ≤ n; 1 ≤ yk ≤ m) — the initial coordinates of the k-th candy. Two candies can lie on the same cell.
Output
For each of the p candies, print on a single line its space-separated new coordinates.
Sample Input
3 3 3 1 1 9 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3
1 3 1 2 1 1 2 3 2 2 2 1 3 3 3 2 3 1
Hint
Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix:
QWER REWQ ASDF -> FDSA ZXCV VCXZ
题意:有三种变换,顺时针旋转90度,镜像,逆时针旋转90度,然后给出矩形大小、翻转次数以及开始坐标。
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
#define ll long long
#define INF 0x3fffffff
#define N 100010 int n,m,x,y,z,k;
pair<int,int> p[N];
int main()
{
while(scanf("%d%d%d%d%d%d",&n,&m,&x,&y,&z,&k)!=EOF)
{
for(int i=;i<=k;i++) scanf("%d%d",&p[i].first,&p[i].second);
x=x%;
y=y%;
z=z%; for(int i=;i<=x;i++) //x
{
for(int j=;j<=k;j++)
{
int tmp=p[j].first;
p[j].first=p[j].second;
p[j].second=n+-tmp;
}
swap(n,m);
}
for(int i=;i<=y;i++) //y
{
for(int j=;j<=k;j++)
{
p[j].second=m+-p[j].second;
}
}
for(int i=;i<=z;i++)
{
swap(n,m);
for(int j=;j<=k;j++)
{
int tmp=p[j].second;
p[j].second=p[j].first;
p[j].first=n+-tmp;
}
}
for(int i=;i<=k;i++) printf("%d %d\n",p[i].first,p[i].second);
}
return ;
}
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Dima took up the biology of bacteria, as a result of his experiments, he invented k types of bacteria. Overall, there are n bacteria at his laboratory right now, and the number of bacteria of type i equals ci. For convenience, we will assume that all the bacteria are numbered from 1 to n. The bacteria of type ci are numbered from to .
With the help of special equipment Dima can move energy from some bacteria into some other one. Of course, the use of such equipment is not free. Dima knows m ways to move energy from some bacteria to another one. The way with number i can be described with integersui, vi and xi mean that this way allows moving energy from bacteria with number ui to bacteria with number vi or vice versa for xidollars.
Dima's Chef (Inna) calls the type-distribution correct if there is a way (may be non-direct) to move energy from any bacteria of the particular type to any other bacteria of the same type (between any two bacteria of the same type) for zero cost.
As for correct type-distribution the cost of moving the energy depends only on the types of bacteria help Inna to determine is the type-distribution correct? If it is, print the matrix d with size k × k. Cell d[i][j] of this matrix must be equal to the minimal possible cost of energy-moving from bacteria with type i to bacteria with type j.
Input
The first line contains three integers n, m, k(1 ≤ n ≤ 105; 0 ≤ m ≤ 105; 1 ≤ k ≤ 500). The next line contains k integersc1, c2, ..., ck(1 ≤ ci ≤ n). Each of the next m lines contains three integers ui, vi, xi(1 ≤ ui, vi ≤ 105; 0 ≤ xi ≤ 104). It is guaranteed that .
Output
If Dima's type-distribution is correct, print string «Yes», and then k lines: in the i-th line print integers d[i][1], d[i][2], ..., d[i][k](d[i][i] = 0). If there is no way to move energy from bacteria i to bacteria j appropriate d[i][j] must equal to -1. If the type-distribution isn't correct print «No».
Sample Input
4 4 2 1 3 2 3 0 3 4 0 2 4 1 2 1 2
Yes 0 2 2 0
3 1 2 2 1 1 2 0
Yes 0 -1 -1 0
3 2 2 2 1 1 2 0 2 3 1
Yes 0 1 1 0
3 0 2 1 2
No
题意:给出n,m和k,表示有n个细菌,m种仪器和k种细菌,给出k种细菌的数量ci,然后每个细菌按照种类排成一排(所以有第i种细菌的序号从∑(1≤j≤i-1)cj + 1 到∑(1≤j≤i)cj);接下来给出m种仪器,有u,v,x三个值,表示说从可以在第u,v号细菌之间移动能量,代价为x。请帮助博士判断说这些细菌是否正确,正确的前提条件是说同种细菌之间移动能量为0,如果正确,给出两两细菌(种类)间移动能量的最小值。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define INF 0x3f3f3f3f
#define N 100010
#define M 510 int n,m,k;
int f[N];
int num[N];
int belong[N];
int mpt[M][M]; int Find(int x)
{
if(x!=f[x]) f[x]=Find(f[x]);
return f[x];
}
void UN(int x,int y)
{
x=Find(x);
y=Find(y);
f[y]=x;
}
bool judge()
{
int i,j,p;
for(i=,p=;i<=k;i++)
{
int x=Find(p);
for(j=;j<=num[i];j++)
if(Find(p++)!=x) return ;
}
return ;
}
void floyd()
{
for(int p=;p<=k;p++)
{
for(int i=;i<=k;i++)
{
for(int j=;j<=k;j++)
{
mpt[i][j]=min(mpt[i][j],mpt[i][p]+mpt[p][j]);
}
}
}
}
int main()
{
int i,j,p;
while(scanf("%d%d%d",&n,&m,&k)!=EOF)
{
memset(mpt,INF,sizeof(mpt));
for(i=;i<=n;i++) f[i]=i;
for(i=,p=;i<=k;i++)
{
scanf("%d",&num[i]);
for(j=;j<=num[i];j++) belong[p++]=i;
}
int u,v,w,uu,vv;
while(m--)
{
scanf("%d%d%d",&u,&v,&w);
if(!w)
UN(u,v);
uu=belong[u];
vv=belong[v];
mpt[uu][vv]=mpt[vv][uu]=min(mpt[uu][vv],w);
}
if(!judge())
{
printf("No\n");
continue;
}
printf("Yes\n");
floyd();
for(i=;i<=k;i++)
{
for(j=;j<=k;j++)
{
if(i==j) mpt[i][j]=;
if(mpt[i][j]==INF) mpt[i][j]=-;
if(j<k) printf("%d ",mpt[i][j]);
else printf("%d",mpt[i][j]);
}
printf("\n");
}
}
return ;
}
Time Limit:3000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Inna is fed up with jokes about female logic. So she started using binary logic instead.
Inna has an array of n elements a1[1], a1[2], ..., a1[n]. Girl likes to train in her binary logic, so she does an exercise consisting of nstages: on the first stage Inna writes out all numbers from array a1, on the i-th (i ≥ 2) stage girl writes all elements of array ai, which consists of n - i + 1 integers; the k-th integer of array ai is defined as follows: ai[k] = ai - 1[k] AND ai - 1[k + 1]. Here AND is bit-wise binary logical operation.
Dima decided to check Inna's skill. He asks Inna to change array, perform the exercise and say the sum of all elements she wrote out during the current exercise.
Help Inna to answer the questions!
Input
The first line contains two integers n and m(1 ≤ n, m ≤ 105) — size of array a1 and number of Dima's questions. Next line contains nintegers a1[1], a1[2], ..., a1[n](0 ≤ ai ≤ 105) — initial array elements.
Each of next m lines contains two integers — Dima's question description. Each question consists of two integers pi, vi(1 ≤ pi ≤ n; 0 ≤ vi ≤ 105). For this question Inna should make a1[pi] equals vi, and then perform the exercise. Please, note that changes are saved from question to question.
Output
For each question print Inna's answer on a single line.
Sample Input
3 4 1 1 1 1 1 2 2 3 2 1 2
6 4 7 12
题意:给出n个数,m个操作,以及a1数组的每个数,然后往下a2数组个数比a1数组少一个数,a2[k]=a2[k]&a2[k+1],直到只有一个数,m次更改a1数组中某个数的值,求这些数组所有数的和。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define ll long long
#define N 100010
#define M 18 ll a[N];
ll ans1,ans2,ans; int main()
{
int i,j,k;
int n,m,x,y;
scanf("%d%d",&n,&m);
for(i=;i<=n;i++) scanf("%I64d",&a[i]); //计算初始情况下的ans
for(k=;k<M;k++)
{
for(i=;i<=n;i++)
{
if((a[i]>>k)&)
{
ans1=ans2=;
for(j=i+;j<=n;j++,i=j)
{
if((a[j]>>k)&) ans2++;
else break;
}
ans+=(ans2*(ans2+)/)<<k;
}
}
}
//m次操作
for(i=;i<m;i++)
{
scanf("%d%d",&x,&y);
for(k=;k<M;k++)
{
ans1=ans2=;
for(j=x-;j>=;j--)
{
if((a[j]>>k)&) ans1++;
else break;
}
for(j=x+;j<=n;j++)
{
if((a[j]>>k)&) ans2++;
else break;
}
if((a[x]>>k)&) ans-=(ans1*ans2)<<k;
if((y>>k)&) ans+=(ans1*ans2)<<k;
}
a[x]=y;
printf("%I64d\n",ans);
}
return ;
}
CodeForces 400的更多相关文章
- codeforces 400 D Dima and Bacteria【并查集 Floyd】
题意:给出n个点,分别属于k个集合,判断每个集合里面的点的距离都为0,为0的话输出yes,并输出任意两个集合之间的最短路 这道题目有两个地方不会处理, 先是n个点,分别属于k个集合,该怎么记录下来这里 ...
- codeforces 400 C Inna and Huge Candy Matrix【模拟】
题意:给出一个矩形的三种操作,顺时针旋转,逆时针旋转,对称,给出原始坐标,再给出操作数,问最后得到的坐标 画一下模拟一下操作就可以找到规律了 #include<iostream> #inc ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem 2-SAT
题目链接:http://codeforces.com/contest/776/problem/D D. The Door Problem time limit per test 2 seconds m ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) A map B贪心 C思路前缀
A. A Serial Killer time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) A
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each ...
- 【第400篇题解纪念2016年10月28日】【28.10%】【codeforces 617E】XOR and Favorite Number
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)
前四题比较水,E我看出是欧拉函数傻逼题,但我傻逼不会,百度了下开始学,最后在加时的时候A掉了 AC:ABCDE Rank:182 Rating:2193+34->2227 终于橙了,不知道能待几 ...
- Codeforces Round #400
最近好像总是有点不想打,专题也刷不动,还是坚持这做了一场,虽然打到一半就没打了...(反正通常都只能做出两题) 感觉自己切水题越来越熟练了,然而难题还是不会做.. A题,水,用vector存下来就行了 ...
- 【2-SAT】【并查集】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem
再来回顾一下2-SAT,把每个点拆点为是和非两个点,如果a能一定推出非b,则a->非b,其他情况同理. 然后跑强连通分量分解,保证a和非a不在同一个分量里面. 这题由于你建完图发现都是双向边,所 ...
随机推荐
- 学习C++ Primer 的个人理解(八)
结束了第一部分,在最后的第七章,我只简单的总结了一下,因为后面还会更详细的说明有关类的内容.而且说实在的这一张的内容让我很不舒服,验证了本书实际上有许多内容是作者的学生一起拼凑而成的.第七章结构给我感 ...
- VPN client on linux debian
Install the pptp-linux and pptp-linux-client: sudo apt-get install pptp-linux pptp-linux-client Crea ...
- js调用asp.net 后台属性值
后台代码: public string title = "js调用后台属性值"; public void getContent() { return title; } 前台代码: ...
- javascripct导图
分别归类为: 1 .javascript变量 2. javascript运算符 3. javascript数组 4. javascript流程语句 5. javascript字符串函数 6. java ...
- js电话号码正则校验--座机和手机号
1.最新的电话号码段: 移动:134(1349除外)135 136 137 138 139 147 150 151 152 157 158 159 182 183 184 187 188 联通: 13 ...
- linux磁盘设备知识
linux分区数字编号: 1.分区数字编号1至4留给主分区或扩展分区使用,逻辑分区编号从5开始. 2.IDE硬盘设备名均以/dev/hd开头,不同硬盘编号依次是/dev/hda/./dev/hdb./ ...
- emctl start dbconsole OC4J_dbconsole*** not found
C:\windows\system32>emctl start dbconsole OC4J Configuration issue. D:\app\product\\db_1/oc4j/j2e ...
- LINQ实战
转载:http://www.cnblogs.com/yubinfeng/p/4567064.html 原作者:尼古拉斯~yu 文章部分内容在原文的基础上有删改. 我相信在net进阶的这个阶段,很 ...
- Codeforces Round #334 (Div. 1) C. Lieges of Legendre
Lieges of Legendre 题意:有n堆牛,每堆有ai头牛.两个人玩一个游戏,游戏规则为: <1>从任意一个非空的堆中移走一头牛: <2>将偶数堆2*x变成k堆,每堆 ...
- componentsJoinedByString 和 componentsSeparatedByString 的方法的区别
将string字符串转换为array数组 NSArray *array = [Str componentsSeparatedByString:@","]; 将array数组转换为 ...